Random Numbers
This program will teach you about the randomizing of numbers. This may seem like a large step, but if the other programs that you made worked that this one will not be all that much trouble to you. I do expect not to tell you that you are going to name these properly now that you pretty well know how to name them. Remember: There are no vowels in the designation and after that, whatever you want.
1.) Open VB and start a Standard EXE
2.) Put in six labels in two columns
Clear out the words from the labels so that the numbers will come up and name the labels, something like : ‘lblRandNum1’ through to ‘lblRandNum6’.
3.) You want to have two command buttons
One of the command buttons will be the ‘Done’ command and you know how to do that. If you don’t remember then you can go back to the pervious exercise and it will be there. The other command will be called ‘Randomize!’. To name this you can just call it ‘cmdRandom’
4.) The code for this program is larger then others.
Start with double clicking on the Randomize! button.
The code in this will be:
Private Sub
cmdRandom_Click()
lblRandNum1.Caption = Int(21 * Rnd + 10)
lblRandNum1.Caption = Int(21
* Rnd + 10)
lblRandNum1.Caption
= Int(21 * Rnd + 10)
lblRandNum1.Caption = Int(21 * Rnd + 10)
lblRandNum1.Caption
= Int(21 * Rnd + 10)
lblRandNum1.Caption
= Int(21 * Rnd + 10)
End Sub
This tells the program that you want the random numbers to range from 10 – 30. Next you want to put some code into the form itself:
Private Sub Form1_Load()
Randomize
End Sub
This completes this program, it wasn’t all that hard, was it?