Solved

# Bouncing Ball

Posted on 2003-12-11
621 Views
I'm trying to make a shape (RedBall), bounce around inside a frame on a form but I'm not sure how to make the IF statement. Any help appreciated.

This is the code I'm using at the mo

If (RedBall.Top < 2400 And RedBall.Left < 3960) Then
RedBall.Top = RedBall.Top + 30
RedBall.Left = RedBall.Left + 30
If (RedBall.Top > 0 And RedBall.Left > 0) Then
RedBall.Top = RedBall.Top - 30
RedBall.Left = RedBall.Left - 30
End If
End If
0
Question by:MonkeyMagic

LVL 13

Accepted Solution

crazyman earned 250 total points
ID: 9919838
Option Explicit

Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
End Sub

Private Sub Timer1_Timer()
Static bVertical As Boolean
Static bHorizontal As Boolean
Select Case RedBall.Top
Case Is > frame1.Height - RedBall.Height
RedBall.Top = RedBall.Top - 10
bVertical = False
Case Is < 0
RedBall.Top = RedBall.Top + 10
bVertical = True
Case Else
If bVertical Then
RedBall.Top = RedBall.Top + 10
Else
RedBall.Top = RedBall.Top - 10
End If
End Select
Select Case RedBall.Left
Case Is > frame1.Width - RedBall.Width
RedBall.Left = RedBall.Left - 10
bHorizontal = False
Case Is < 0
RedBall.Left = RedBall.Left + 10
bHorizontal = True
Case Else
If bHorizontal Then
RedBall.Left = RedBall.Left + 10
Else
RedBall.Left = RedBall.Left - 10
End If
End Select
End Sub
0

LVL 16

Expert Comment

ID: 9919935
There is an example in VB installation regarding this.
0

## Featured Post

### Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…