Q:

How can I change a variable when 2 objects collide?

I am trying to make a very, very basic pong game and need some help with object collisions. When I run the following code, and start the program, the ball moves right across the screen, however when it hits the paddle, it starts going left for as long as it is touching the paddle, but then goes right again, and gets stuck in a loop. This is probably a pretty basic problem but some help would be appreciated, thanks.
    Dim direction As Integer = 0

    If ball.Bounds.IntersectsWith(paddle1.Bounds) Then
        direction = 1
    End If

    If ball.Bounds.IntersectsWith(paddle2.Bounds) Then
        direction = 2
    End If

    If direction = 2 Then
        ball.Left += 15
    End If

    If direction = 1 Then
        ball.Left -= 15
    End If
End Sub

A:

Figured it out, I had declared "direction" inside the Timer, so it was constantly going right.

