Bouncing Ball

Posted on 2003-12-11
Medium Priority
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
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
LVL 13

Accepted Solution

crazyman earned 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

777 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