Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Bouncing Ball

Posted on 2003-12-11
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
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
                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
                    RedBall.Left = RedBall.Left - 10
                End If
        End Select
End Sub
LVL 16

Expert Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

860 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