power ball genartor

VB Help~Power Ball Genarator by: vbx23

 

If any of these confuse you then check my Begining Programing Section, it will cover all of the basic terms.

If you want to download the Power_Ball program Click Here.

What is Power Ball you might ask? It's a lotto, I found out about it when I went to South Dakota and visited my relatives. My Aunt has been testing it, you can say and she has helped me programed it. Now I will help you program it. There are 6 Balls that come up with numbers, if you have some of the numbers or all you win some money but the program only picks numbers, it dosent give you money.

 

The following code is how I programed Power Ball, its long but not complexed.

 

First add 6 labels Which will be the Possible Balls. Make them about the same size and same font and forecolor. The labels should be aligned in the middle. The Label's Caption's should be Ball1, Ball2 and so on. Add another Label on top of all of the Ball labels and call it Label1, the Caption should be "Caculating". There is no programing codes for the labels in this program, but you can add some if you wanted.

Add a command button. I added a image that says Click Here but the button will do. Also add a Label above all of the other labels you put in that represent the balls.

Caption: Click Here

Name: Command1 it doesnt matter as long as you know it, just use Command1 for this program.

Double Click the button and put in the following code:

Private Sub Command1_Click()
Timer1.Enabled = True
Label1.Caption = "Caculating...."
Label1.Visible = True
End Sub

Ok, lets break this down. Command1 is the name of the button, by putting it in the code it allows VB to reconize it. Label1 is what I use to make the program seem more complexed, all it does is pause the program so that it takes a couple of seconds to give you the numbers. During the time it says caculating. The Timer1 is a Timer that pauses the program to make it look more professional. I'll come back to the timer because it is the heart of the program.

Double Click the Form so your not in a button or nothing and insert the following code:

Private Sub Form_Load()
Randomize
MsgBox "Remember To Right Down Your Power Ball Numbers", vbInformation, "Power Ball #'s"
End Sub

The Randomize will prevent the Balls from showing up in a certain order. The code MsgBox "Remember To Right Down..." stands for Message Box, cause the form is loading it will bring up a box saying "Remember To Right Down..." and the rest of the sentence. Your'll see when you run the program.

You'll have to refer to my menu section to know how to do the next part. Add a menu &File and under put &About. Name About "mnuAbout" and insert the following code:

Private Sub mnuAbout_Click()
MsgBox "Power Ball v1.1 Programed by: Douglas Hedges", vbInformation, "About"
End Sub

Create another menu under File that is called Exit, this will close the program. Name: mnuE&xit Caption: Exit, and add the following:

Private Sub mnuExit_Click()
End
End Sub

Now for the heart of the program, the Timers. I had trouble when I first created my Power Ball Genartor, it would sometimes add 0, but there are no zeros in the Power Ball lotto, so I added Timers. Add Timer1, if you havent all ready Interval: 1500. Add another Timer Name: Timer2 Interval: 1500. Under Timer1 insert the following code:

Private Sub Timer1_Timer()
Label1.Visible = False
Ball1.Caption = Int(Rnd * 50)
Ball2.Caption = Int(Rnd * 50)
Ball3.Caption = Int(Rnd * 50)
Ball4.Caption = Int(Rnd * 50)
Ball5.Caption = Int(Rnd * 50)
Ball6.Caption = Int(Rnd * 43)
Timer1.Enabled = False
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If (Ball1.Caption = 0) Or (Ball2.Caption = 0) Or _
(Ball3.Caption = 0) Or (Ball4.Caption = 0) Or _
(Ball5.Caption = 0) Or (PowerBall.Caption = 0) Then
Ball1.Caption = ""
Ball2.Caption = ""
Ball3.Caption = ""
Ball4.Caption = ""
Ball5.Caption = ""
PowerBall.Caption = ""
Timer2.Enabled = True
Command1.Visible = False
Caculating.Caption = "Error, Caculating...."
End If
End Sub

To break it down the begging says Ball1 = Int(Rnd * 50) what this does is simple, Int is like dimiension or something, Rnd * 50 means that it randomly picks a number less then 50 because of Int instead of Rnd Times 50. Time1.Disabled ends the random numbers or else it would pick new numbers every second and a half.

I used the '~~~~~~ to separate the code so I wouldn't get confused, by puttina ' infront of ~~~~~ it reconized that it wasnt a code and that it was a note.

It says If Ball1 = 0 or any of em. I put them in ( ) so it wouldn't get confused, if it does = 0 i had it say Error and clear the caption then start Timer2 to start the random numbers over again.

Put in the following Code for Timer2 and I'll explain.

Private Sub Timer2_Timer()
Timer1.Enabled = True
Timer1.Enabled = False
Command1.Visible = True
End Sub

I created another Timer to enable Timer1 again to pick new numbers but it wouldn't work haveing Timer1.Disabled and Timer1.Enabeled in the same code. I also made the button disappear so that someone wouldn't try to click it and mess up the numbers.

There you have now try running the program.

If you have any problems e-mail me at vbx23@aol.com

 

CopyRight© 99-00 - ALL RIGHTS RESERVED

1