**A Bouncing Ball**

By | 2002-06-01

This code shows a circle bouncing off of the sides of the form like Jezzball (But not as good).

Original Author: Ben Doherty

Assumptions

you need to make 2 timers named Timer1 and Timer2, make a circle shape
and name it pic. set the background color to black.

Code

Private Sub Form_Load()
Form1.Height = 4770
Form1.Width = 5865
Form1.BackColor = &H0
pic.BorderColor = &HFF&
pic.Top = 0
pic.Left = 0
End Sub
Private Sub Timer1_Timer()
If Timer1.Interval = 1 Then   ' this is the code that
pic.Left = pic.Left - 40    ' makes the ball bounce
If pic.Left < -100 Then
Timer1.Interval = 2
Beep
Else
pic.Left = pic.Left - 40
End If
End If

If Timer1.Interval = 2 Then
pic.Left = pic.Left + 40
If pic.Left > 4790 Then
Timer1.Interval = 1
Beep
Else
pic.Left = pic.Left + 40
End If
End If
End Sub
Private Sub Timer2_Timer()
If Timer2.Interval = 1 Then
pic.Top = pic.Top - 40
If pic.Top = 0 Then
Timer2.Interval = 2
Beep
Else
pic.Top = pic.Top - 40
End If
End If
If Timer2.Interval = 2 Then
pic.Top = pic.Top + 40
If pic.Top = 3480 Then
Timer2.Interval = 1
Beep
Else
pic.Top = pic.Top + 40
End If
End If
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.