This sub moves a rectangle to the center of the form and when it gets there it moves back to its original location. But something weird has happened and the rectangle still moves, but the boolean values dont change. I tested to see if that part of the code was executed by putting a messagebox where the boolean values are supposed to change and the messagebox didnt appear. Help would be greatly appreciated.
Here is the sub:
Code:
 Public Sub Start()
        Dim Energy As New PictureBox
        _IsMoving = True 'here is the boolean values along with some other variables
        MessageBox.Show("") 'Here is the messagebox
        _HasEnergy = False 'here is the boolean values along with some other variables
        _EnergyIndex = -1
        Do Until Not Energy.Bounds.IntersectsWith(Form1.ClientRectangle)
            If Not _HasEnergy Then
                Select Case _Index
                    Case 0
                        Rect.Location = New Point(Rect.Left + 1, Rect.Top + 1)
                    Case 1
                        Rect.Location = New Point(Rect.Left + 0, Rect.Top + 1)
                    Case 2
                        Rect.Location = New Point(Rect.Left - 1, Rect.Top + 1)
                    Case 3
                        Rect.Location = New Point(Rect.Left - 1, Rect.Top + 0)
                    Case 4
                        Rect.Location = New Point(Rect.Left - 1, Rect.Top - 1)
                    Case 5
                        Rect.Location = New Point(Rect.Left + 0, Rect.Top - 1)
                    Case 6
                        Rect.Location = New Point(Rect.Left + 1, Rect.Top - 1)
                    Case 7
                        Rect.Location = New Point(Rect.Left + 1, Rect.Top + 0)
                End Select
                For i = 0 To 9
                    If Rect.IntersectsWith(Form1.Controls("Energy" & i).Bounds) Then
                        _HasEnergy = True
                        Energy = Form1.Controls("Energy" & i)
                        _EnergyIndex = i
                        Exit For
                    End If
                Next i
            Else
                Select Case _Index
                    Case 0
                        Rect.Location = New Point(Rect.Left - 1, Rect.Top - 1)
                    Case 1
                        Rect.Location = New Point(Rect.Left - 0, Rect.Top - 1)
                    Case 2
                        Rect.Location = New Point(Rect.Left + 1, Rect.Top - 1)
                    Case 3
                        Rect.Location = New Point(Rect.Left + 1, Rect.Top - 0)
                    Case 4
                        Rect.Location = New Point(Rect.Left + 1, Rect.Top + 1)
                    Case 5
                        Rect.Location = New Point(Rect.Left - 0, Rect.Top + 1)
                    Case 6
                        Rect.Location = New Point(Rect.Left - 1, Rect.Top + 1)
                    Case 7
                        Rect.Location = New Point(Rect.Left - 1, Rect.Top - 0)
                End Select
                If Not Rect.IntersectsWith(Form1.ClientRectangle) Then
                    Form1.Lives -= 1
                    _HasEnergy = False
                    _IsMoving = False
                    _EnergyIndex = -1
                    Exit Do
                    Exit Sub
                End If
            End If
            Application.DoEvents()
            Threading.Thread.Sleep(1)
        Loop
    End Sub