Lucky Lotto
Learn to make a Lucky Lotto example using Visual Basic 6 with this Tutorial that Celebrates the CESPage 25th Anniversary
This is a simple program, which will introduce you to Control Arrays, Standard Arrays, Label Control and Random Number Generation!
Step 1
![New Project](../assets/fignewproject.gif)
Step 2
![Blank Form](../assets/figform1.gif)
Step 3
![Label Control](../assets/figlbl.gif)
Step 4
![Form with Label Control](../assets/figfrmlbl.gif)
Step 5
Name
of Label1
to lblNumber
![Label Name Property](../assets/figlblprop.gif)
Step 6
lblNumber
and Copy it
![Copy](../assets/figcopy.gif)
![Paste](../assets/figpaste.gif)
lblNumbers
"s)
![Form with Six Labels](../assets/figfrmlabels.gif)
Step 7
![Command Button Control](../assets/figcommand.gif)
Step 8
Name
Property of Command1
to cmdChoose
,
the Caption
Property to Choose
and the Name
of Command2
to cmdQuit
and the Caption
to Quit
![Form with Six Labels and Two Command Buttons](../assets/figfrmlblcmd.gif)
Step 9
Click on the Form
and change its Name
Property to frmMain
then Double Click on the Form of frmMain
and type in the Form_Load
Sub:
Dim i As Integer
For i = 0 To 5
lblNumber(i).Caption = ""
Next i
Step 10
Double Click on the Command Button of Choose or cmdChoose
and type in the cmdChoose_Click()
Sub:
Dim arrNumber(1 To 6) As Integer ' Array
Dim intLucky As Integer ' Random Number
Dim intCount As Integer ' Selection Counter
Dim intCheck As Integer ' Previous Selection Counter
For intCount = 1 To 6 ' Select Six Numbers
Start: ' Start Point
Randomize (Timer) ' Seed Randomiser
intLucky = Int((49 * Rnd) + 1) ' Random number 1 to 49
For intCheck = 1 To 6
If intLucky = arrNumber(intCheck) Then
GoTo Start 'If selected number already present, select again
End If
Next intCheck
arrNumber(intCount) = intLucky ' Store selected number in array
lblNumber(intCount - 1) = arrNumber(intCount) ' apply selection to labels
Next intCount
Step 11
Double Click on the Command Button of Quit or cmdQuit
and type in the cmdQuit_Click()
Sub:
Unload Me
Step 12
![Start / Run](../assets/figstart.gif)
![Lucky Lotto Running](../assets/figlottorun.gif)
Step 13
![Lucky Lotto Chosen](../assets/figlottosel.gif)
Step 14
![End / Stop](../assets/figend.gif)
You have just created a simple Random Number generator! Try adding extras such as colours and other effects and see what else you can achieve with this program.