Just starting to program, 1st assignment was to create lottery interface for randomize numbers 1- 54. displays 6 lottery numbers separate label control, Print button printing w/o command buttons showing, and an exit button. So far this is what I've done for coding what am I missing or doing wrong?

Private Sub RandomNumbers()
Dim intTemp As Integer
Randomize 'generate random numbers
intNum1 = Int((54 - 1 + 1) * Rnd + 1)
intNum2 = Int((54 - 1 + 1) * Rnd + 1)
intNum3 = Int((54 - 1 + 1) * Rnd + 1)
intNum4 = Int((54 - 1 + 1) * Rnd + 1)
intNum5 = Int((54 - 1 + 1) * Rnd + 1)
intNum6 = Int((54 - 1 + 1) * Rnd + 1)
End Sub

Private Sub Command1_Click()
Randomize

Label1.Caption = Str(Int(Rnd * 54) + 1)
Label2.Caption = Str(Int(Rnd * 54) + 1)
Label3.Caption = Str(Int(Rnd * 54) + 1)
Label4.Caption = Str(Int(Rnd * 54) + 1)
Label5.Caption = Str(Int(Rnd * 54) + 1)
Label6.Caption = Str(Int(Rnd * 54) + 1)

If (Label1 = Label2) Or (Label1 = Label3) Or (Label1 = Label4) Or (Label1 = Label5) Or (Label1 = Label6) Then Label1.Caption = Str(Int(Rnd * 54) + 1)
End If
If (Label2 = Label1) Or (Label2 = Label3) Or (Label2 = Label4) Or (Label2 = Label5) Or (Label2 = Label6) Then Label2.Caption = Str(Int(Rnd * 54) + 1)
End If
If (Label3 = Label1) Or (Label3 = Label2) Or (Label1 = Label4) Or (Label3 = Label5) Or (Label3 = Label6) Then Label3.Caption = Str(Int(Rnd * 54) + 1)
End If
If (Label4 = Label1) Or (Label4 = Label2) Or (Label1 = Label3) Or (Label4 = Label5) Or (Label4 = Label6) Then Label4.Caption = Str(Int(Rnd * 54) + 1)
End If
If (Label5 = Label1) Or (Label5 = Label2) Or (Label1 = Label3) Or (Label5 = Label4) Or (Label5 = Label6) Then Label5.Caption = Str(Int(Rnd * 54) + 1)
End If
If (Label6 = Label1) Or (Label6 = Label2) Or (Label1 = Label3) Or (Label6 = Label4) Or (Label6 = Label5) Then Label6.Caption = Str(Int(Rnd * 54) + 1)
End If
End Sub


End Sub

Private Sub Form_Load()

End Sub

Hi,

The problem is the End If you have added.

see below:

Private Sub RandomNumbers()
Dim intTemp As Integer
Randomize 'generate random numbers
intNum1 = Int((54 - 1 + 1) * Rnd + 1)
intNum2 = Int((54 - 1 + 1) * Rnd + 1)
intNum3 = Int((54 - 1 + 1) * Rnd + 1)
intNum4 = Int((54 - 1 + 1) * Rnd + 1)
intNum5 = Int((54 - 1 + 1) * Rnd + 1)
intNum6 = Int((54 - 1 + 1) * Rnd + 1)
End Sub

Private Sub Command1_Click()
Randomize

Label1.Caption = Str(Int(Rnd * 54) + 1)
Label2.Caption = Str(Int(Rnd * 54) + 1)
Label3.Caption = Str(Int(Rnd * 54) + 1)
Label4.Caption = Str(Int(Rnd * 54) + 1)
Label5.Caption = Str(Int(Rnd * 54) + 1)
Label6.Caption = Str(Int(Rnd * 54) + 1)

If (Label1 = Label2) Or (Label1 = Label3) Or (Label1 = Label4) Or (Label1 = Label5) Or (Label1 = Label6) Then Label1.Caption = Str(Int(Rnd * 54) + 1)
If (Label2 = Label1) Or (Label2 = Label3) Or (Label2 = Label4) Or (Label2 = Label5) Or (Label2 = Label6) Then Label2.Caption = Str(Int(Rnd * 54) + 1)
If (Label3 = Label1) Or (Label3 = Label2) Or (Label1 = Label4) Or (Label3 = Label5) Or (Label3 = Label6) Then Label3.Caption = Str(Int(Rnd * 54) + 1)
If (Label4 = Label1) Or (Label4 = Label2) Or (Label1 = Label3) Or (Label4 = Label5) Or (Label4 = Label6) Then Label4.Caption = Str(Int(Rnd * 54) + 1)
If (Label5 = Label1) Or (Label5 = Label2) Or (Label1 = Label3) Or (Label5 = Label4) Or (Label5 = Label6) Then Label5.Caption = Str(Int(Rnd * 54) + 1)
If (Label6 = Label1) Or (Label6 = Label2) Or (Label1 = Label3) Or (Label6 = Label4) Or (Label6 = Label5) Then Label6.Caption = Str(Int(Rnd * 54) + 1)

End Sub

One problem I can see is you are not checking if the six numbers are unique.
i.e.
If Label6 = Label1 then you are getting another random number. What if the number generated was the same as, say, label 2.

Cheers,
pG

hi, i'm just a new user of this site. i just want to ask about visual basic program. could you help me make a chess game program using visual basic? please? thank you in advance!

hi, i'm just a new user of this site. i just want to ask about visual basic program. could you help me make a chess game program using visual basic? please? thank you in advance!

Hi,

Users on this forum are very helpful and would help you any way they can. You will get a better response by creating a new post in the forum.

Anyways, have you started the app yet? Is there one bit you are stuck on? Is it a personal project or a school assignment?

Cheers,
PG

This article has been dead for over six months. Start a new discussion instead.