hi to everyone :)

If c >= 17 Then
            PictureBox17.Location = PictureBox16.Location
        End If

        If c >= 16 Then
            PictureBox16.Location = PictureBox15.Location
        End If

        If c >= 15 Then
            PictureBox15.Location = PictureBox14.Location
        End If

        If c >= 14 Then
            PictureBox14.Location = PictureBox13.Location
        End If

        If c >= 13 Then
            PictureBox13.Location = PictureBox12.Location
        End If

        If c >= 12 Then
            PictureBox12.Location = PictureBox11.Location
        End If

        If c >= 11 Then
            PictureBox11.Location = PictureBox10.Location
        End If


        If c >= 10 Then
            PictureBox10.Location = PictureBox9.Location
        End If
        If c >= 9 Then
            PictureBox9.Location = PictureBox8.Location
        End If
        If c >= 8 Then
            PictureBox8.Location = PictureBox7.Location
        End If
        If c >= 7 Then
            PictureBox7.Location = PictureBox6.Location
        End If
        If c >= 6 Then
            PictureBox6.Location = PictureBox5.Location
        End If
        If c >= 5 Then
            PictureBox5.Location = PictureBox4.Location
        End If
        If c >= 4 Then
            PictureBox4.Location = PictureBox3.Location
        End If
        If c >= 3 Then
            PictureBox3.Location = PictureBox2.Location
        End If
If c = 5 Then
                PictureBox5.Location = PictureBox4.Location
                c = 6
            ElseIf c = 6 Then
                PictureBox6.Location = PictureBox5.Location
                c = 7
            ElseIf c = 7 Then
                PictureBox7.Location = PictureBox6.Location
                c = 8
            ElseIf c = 8 Then
                PictureBox8.Location = PictureBox7.Location
                c = 9
            ElseIf c = 9 Then
                PictureBox9.Location = PictureBox8.Location
                c = 10
            ElseIf c = 10 Then
                PictureBox10.Location = PictureBox9.Location
                c = 11

            ElseIf c = 11 Then
                PictureBox11.Location = PictureBox10.Location
                c = 12
            ElseIf c = 12 Then
                PictureBox12.Location = PictureBox11.Location
                c = 13
            ElseIf c = 13 Then
                PictureBox13.Location = PictureBox12.Location
                c = 14
            ElseIf c = 14 Then
                PictureBox14.Location = PictureBox13.Location
                c = 15
            ElseIf c = 15 Then
                PictureBox15.Location = PictureBox14.Location
                c = 16
            ElseIf c = 16 Then
                PictureBox16.Location = PictureBox15.Location
                c = 17
            ElseIf c = 17 Then
                PictureBox17.Location = PictureBox16.Location
                c = 18

            End If

I'm making a Snake game with these codes, but its to long i want to make it shorter and simpler.
how can i do that?
btw, i'm using Visual Studio 2008
:-/

Thank you.

uhmm, i tried this but i the for loop does not execute properly.

For x As Integer = 3 To 8
            If c >= x Then
                y = x - 1
                Me.Controls("PictureBox" & x).Location = Me.Controls("PictureBox" & y).Location
            End If
        Next
For x As Integer = 5 To 8
            If c = x Then
                y = x - 1
                Me.Controls("PictureBox" & x).Location = Me.Controls("PictureBox" & y).Location
                x = x + 1
            End If
        Next

please help

For this one :

If c >= 17 Then
            PictureBox17.Location = PictureBox16.Location
        End If

        If c >= 16 Then
            PictureBox16.Location = PictureBox15.Location
        End If

        If c >= 15 Then
            PictureBox15.Location = PictureBox14.Location
        End If

        If c >= 14 Then
            PictureBox14.Location = PictureBox13.Location
        End If

        If c >= 13 Then
            PictureBox13.Location = PictureBox12.Location
        End If

        If c >= 12 Then
            PictureBox12.Location = PictureBox11.Location
        End If

        If c >= 11 Then
            PictureBox11.Location = PictureBox10.Location
        End If


        If c >= 10 Then
            PictureBox10.Location = PictureBox9.Location
        End If
        If c >= 9 Then
            PictureBox9.Location = PictureBox8.Location
        End If
        If c >= 8 Then
            PictureBox8.Location = PictureBox7.Location
        End If
        If c >= 7 Then
            PictureBox7.Location = PictureBox6.Location
        End If
        If c >= 6 Then
            PictureBox6.Location = PictureBox5.Location
        End If
        If c >= 5 Then
            PictureBox5.Location = PictureBox4.Location
        End If
        If c >= 4 Then
            PictureBox4.Location = PictureBox3.Location
        End If
        If c >= 3 Then
            PictureBox3.Location = PictureBox2.Location
        End If

You can compress it using a loop :

for(int c = 17; c >= 3; --c){
 PictureBox[c].location = PictureBox[c-1].location;
}

Do the same with the other.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.