Solved

Bouncing Ball

Posted on 2003-12-11
2
663 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

696 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