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

Edited 5 Years Ago by djjavo: n/a

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)

Edited 5 Years Ago by codeorder: n/a

sorry i haven't replied in a while, totally forgot about this thread!

unfortunately the suggested code does not work :(

just to clarify i have 24 pictureboxes and would like to do that case statement on all of them. i currently have it working as i wrote each one out individually but if you could do one case statement when all 24 pictureboxes follow that it would be alot quicker to write ;)

thanks again!

This article has been dead for over six months. Start a new discussion instead.