Hi

I know there are some posts addressing the same issue but unfortunately I do not understand how to do it and was wondering if someone could help.

I would like to cycle through pictureboxes, in this example using the 'n' variable
To further explain what I would like to do, I need the n to be the same for the array as the picturebox number, looping from 1 to 24, and depending on what data is in that array, controls what picture the corresponding picturebox displays.

I know this code won't work, but this is me trying to demonstrate what I need to happen.
Also the file paths are not correct, as this is just for demonstration purposes.

Dim n As Integer
For n = 1 To 24
Select Case f1data(n).countries
Case "GER"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\de.gif")
Case "AUS"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\au.gif")
Case "GBR"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\gb.gif")
Case "ESP"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\es.gif")
Case "BRA"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap(\bin\flags\br.gif")
Case "RUS"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\ru.gif")
Case "VEN"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\ve.gif")
Case "JPN"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\jp.gif")
Case "MEX"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\mx.gif")
Case "CHE"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\ch.gif")
Case "FIN"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\fi.gif")
Case "ITA"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\it.gif")
Case "IND"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\in.gif")
Case "BEL"
Form2.PictureBoxn.Image = New System.Drawing.Bitmap("\bin\flags\be.gif")
End Select
Next

If you have a solution for me that would be fantastic.

Cheers

If you just need to get the "n" value, see if this helps.

Dim iSelectedN As Integer = 0 '// stores the "n" value for use.
For n As Integer = 1 To 24
iSelectedN = n '// set value from loop.
With Form2.PictureBoxn
Select Case f1data(n).countries …

## All 2 Replies

If you just need to get the "n" value, see if this helps.

Dim iSelectedN As Integer = 0 '// stores the "n" value for use.
For n As Integer = 1 To 24
iSelectedN = n '// set value from loop.
With Form2.PictureBoxn
Select Case f1data(n).countries
Case "GER"
.Image = New System.Drawing.Bitmap("\bin\flags\de.gif")
Exit For '// Exit the For/Next loop since done.
Case "AUS"
.Image = New System.Drawing.Bitmap("\bin\flags\au.gif")
Exit For '// Exit the For/Next loop since done.
Case "GBR"
.Image = New System.Drawing.Bitmap("\bin\flags\gb.gif")
Exit For '// Exit the For/Next loop since done.

'// etc...
End Select
End With
Next
MsgBox("n = " & iSelectedN.ToString)