Compile Error

R

Richard

Hi I am trying to use this random number generator, I get a compile error:
Sub or function not defined.

' 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: (e-mail address removed)

Private Sub Command1_Click()

Dim Lottery(6) As Integer ' array to hold final selected
numbers
Dim nLucky As Integer ' variable to hold each random
selection
Dim nCount As Integer ' counter for number of
selections made
Dim nCheck As Integer ' counter for check on previous
selections

For nCount = 1 To 6 ' choose 6 numbers
Start: ' 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


the program highlites on this code: Label1(nCount - 1) =
also yellow arrow on this code: Private Sub Command1_Click()

Thanks for your help.
 
J

John Spencer

I am guessing that you have controls that are named Label10, Label11,
Label12, Label13, Label14 and Label15. If so, you can refer to them as

Me("Label1" & nCount-1) = Lottery(ncount)

If the controls are labels and not textboxes then you probably want

Me("Label1" & nCount-1).Caption = Lottery(ncount)




'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
R

Richard

yes that did it ty

John Spencer said:
I am guessing that you have controls that are named Label10, Label11,
Label12, Label13, Label14 and Label15. If so, you can refer to them as

Me("Label1" & nCount-1) = Lottery(ncount)

If the controls are labels and not textboxes then you probably want

Me("Label1" & nCount-1).Caption = Lottery(ncount)




'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top