This is a simple variation of the old "Pong" game that popularized video games. You will learn some simple animation techniques in Visual Basic.

Step 1: Design the Form

 

Step 2: Set the Properties

Object Name Properties
Form frmPong Caption Pong
Command Button cmdExit Caption Exit
Command Button cmdStartStop Caption Start
Timer Timer1 Enabled False
Interval 10
Shape shpBall1 FillStyle Solid
Shape Circle
Line Line1 X1
X2
Y1
Y2
Line Line2 X1
X2
Y1
Y2

 

Step 3: Write the Code

Private MoveLeft, LeftPos As Integer <--In General Declarations

Sub cmdStartStop_Click ()

If the timer1 is enabled Then

Disable it
Change StartStop caption to "Start"

Else

Enable it
Change StartStop caption to "Stop"

End Sub

Sub Form_Load ()

Set MoveLeft to True

End Sub

Sub Timer1_Timer ()

If MoveRight is true Then

Move the ball to the right (shpBall1.Left = shpBall1.Left + 50)

Else

Move the ball to the left (shpBall1.Left = shpBall1.Left - 50)

End If

'see if ball hit left line

If LeftPos <= (the left position) Then

Set MoveRight to True

End If

Move shpBall to LeftPos

' see if ball hit right line

If (the left position) + (the width of the ball) >= (the right position) Then

Set MoveRight to False

End If

End Sub