Bouncing ball program in visual basic 6.0
Are you working on a visual basic graphic and animation program and want to create a bouncing ball program in vb6. Then here I have given the best solution for you because we are always ready to provide help for your problems. In this program, you can learn how to create a bouncing ball program in visual basic 6.0. For creating this program you need some knowledge about the visual basic graphical and animation coding.
Sometimes students are searching for how to make a bouncing ball animation in vb 6.0. If you are interested to create this visual basic program then you can join us for getting an easy visual basic program. You can see our other visual basic programs example of how to write program to find freehand drawing in vb6.0. This is a simple drawing application in visual basic 6.0. Now here in this program, we can learn how to make a bouncing ball application in vb6?
This is a very easy solution for a visual basic bouncing ball program. If you want to develop something new then you can just follow the following steps. By using those steps you can try something new.
Steps for making bouncing ball program in visual basic 6.0
- First, create a new form.
- Then draw a picture box control and set that picture box property as a ‘None’ and set the ball picture by using the picture property.
- After that, write the below coding on the form.
- Then run the program.
- Note: Here this program I have given picture box name is ‘ball’
Easy Source code for the visual basic bouncing ball program.
Public blnReady As Boolean
Public Motion
Dim r
Dim G
Dim B
Private Sub Form_Click()
blnReady = True
End Sub
Private Sub Form_Load()
Me.Show
Motion = Int(4 * Rnd + 1)
blnReady = False
Do While Not blnReady
Call BouncingBall
EvenWachten
DoEvents
Loop
End Sub
Public Sub BouncingBall()
r = 255 * Rnd
G = 255 * Rnd
B = 255 * Rnd
With frmBouncingBall
Select Case Motion
Case 1
.ball.Move .ball.Left - 20, .ball.Top - 20
If .ball.Left <= 0 Then
Motion = 2
.ball.FillColor = RGB(r, G, B)
ElseIf .ball.Top <= 0 Then
Motion = 4
.ball.FillColor = RGB(r, G, B)
End If
Case 2
.ball.Move .ball.Left + 20, .ball.Top - 20
If .ball.Left >= (.Width - .ball.Width) Then
Motion = 1
.ball.FillColor = RGB(r, G, B)
ElseIf .ball.Top <= 0 Then
Motion = 3
.ball.FillColor = RGB(r, G, B)
End If
Case 3
.ball.Move .ball.Left + 20, .ball.Top + 20
If .ball.Left >= (.Width - .ball.Width) Then
Motion = 4
.ball.FillColor = RGB(r, G, B)
ElseIf .ball.Top >= (.Height - .ball.Height) - 80 Then
Motion = 2
.ball.FillColor = RGB(r, G, B)
End If
Case 4
.ball.Move .ball.Left - 20, .ball.Top + 20
If .ball.Left <= 0 Then
Motion = 3
.ball.FillColor = RGB(r, G, B)
ElseIf .ball.Top >= (.Height - .ball.Height) - 80 Then
Motion = 1
.ball.FillColor = RGB(r, G, B)
End If
End Select
End With
End Sub
Public Sub EvenWachten()
Dim Start
Dim Check
Start = Timer
Do Until Check >= Start + 0.01
Check = Timer
Loop
End Sub
Important Note: After running the program sometimes the program will not be closed by clicking on the forms (cross) close button then you just press the stop. Otherwise, you can create your own separate button in the form for the end of the program execution.
How to work the bouncing ball program in visual basic 6
The working process of this program is very simple, after the execution of the program the ball will be bouncing automatically. In the coding, I have used the select case statement and do while loop. But here maybe most of the students will be confused in source coding because here I have used the r G and B variables. But don’t worry about that if you study that coding properly then you will understand.
I know that this text format is very boring to understand so that I will provide an easy video on youtube due to that you can easily understand that how to make a bouncing ball animation in vb6. Normally, the ball is in picture box control, therefore, we need the image in gif format, if you use the png or jpg image maybe that image will not be displayed in that picture box control.
Why do we need a visual basic bouncing ball program
When you create this type of program in visual basic then you can develop your programming logic. Because here in this program we are using the select case statement and until loop statement for our programming logic. This program is not more useful for advanced visual basic programmers but this will be very helpful for beginners.
Sometimes this program is called the jumping ball program in vb6. So that doesn’t confuse these programs are work multiple types like at the ball you can use the carrom board. Here we want to focus on the programming logic. Because once you clear your logic then you can that programming logic in any other programming language in which where you can create the program through the GUI like vb .net or c# etc.
To create the bouncing ball animation in vb6 then you need to know about the basic visual basic animations. When you create this program in any other programming language then you need to know the bouncing ball algorithm. If you are still confused about how to make a bouncing ball program in visual basic then comment to me I will provide another post or video for you.
0 Comments