?
Solved

Bouncing Ball

Posted on 2003-12-11
2
Medium Priority
?
667 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
[X]
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
2 Comments
 
LVL 13

Accepted Solution

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

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