Solved

Bouncing Ball

Posted on 2003-12-11
2
621 Views
Last Modified: 2010-05-01
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
Comment
Question by:MonkeyMagic
2 Comments
 
LVL 13

Accepted Solution

by:
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

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now