' Random number selector program, chooses 6 numbers 1-49 without duplication, used for UK lottery.
' Assumes form with button Command1 and six-label array Label1(0) to Label1(5) without captions.
' ©Mike McGrath 1998 eMailto: mikem@clara.net
Private Sub Command1_Click()
im Lottery(6) As Integer ' array to hold final selected numbers
im nLucky As Integer ' variable to hold each random selection
im nCount As Integer ' counter for number of selections made
im nCheck As Integer ' counter for check on previous selections
or nCount = 1 To 6 ' choose 6 numbers
tart: ' lets go (again)
Randomize ' random-seed the random generator
nLucky = Int((49 * Rnd) + 1) ' pick random number from 1 to 49
For nCheck = 1 To 6
If nLucky = Lottery(nCheck) Then ' if seleced number has already been picked...
GoTo Start ' go back and pick another number.
End If
Next nCheck
Lottery(nCount) = nLucky ' store selection in array
Label1(nCount - 1) = Lottery(nCount) ' apply selection to labels (-1 for 0 to 5)
Next nCount
End Sub
-----------------------------------------------------------------------------------------------------------
' "Slot-machine" random selector, chooses from color choice with spin simulation, displays score.
' Assumes form with button Command1 and three-label array Label1(0) to Label1(2), also label named
' lblWinnings with caption 1000. © Mike McGrath 1998 eMailto: mikem@clara.net
Private Sub Command1_Click()
im Jackpot(3) As Integer ' array to hold final selection
im nColor As Integer ' variable for color selection
im nCount As Integer ' counter for selections made
im nSpin As Integer ' counter for spintime
For nSpin = 1 To 100
For nCount = 1 To 3 ' pick 3 backcolors
Randomize ' random-seed random generator
nColor = Int((Rnd * 5) + 1) ' pick from 1 to 4
Jackpot(nCount) = nColor ' store selection in array
Label1(nCount - 1).BackColor = QBColor(nColor) ' apply selection to label...
Next nCount ' (-1 for label 0 to 2)
orm1.Refresh ' spin (just for effect)
Next nSpin
If Jackpot(1) = Jackpot(2) And Jackpot(2) = Jackpot(3) Then
lblWinnings.Caption = lblWinnings.Caption + 500 ' 3-of-a-kind wins 500
ElseIf Jackpot(1) = Jackpot(2) Then
lblWinnings.Caption = lblWinnings.Caption + 100 ' 2-of-a-kind in 1 & 2 wins 100
Else
lblWinnings.Caption = lblWinnings.Caption - 50 ' loses stake of 50
End If
End Sub
Downloads
In IE right-click and select 'Save Target As...' or in Netscape
right-click and select 'Save Link As...'
View Plain Text
Download Demo Project
Not Available