ninjalearner
New Member
Dear All, I have written the codes below, it returns text as result and keep running endlessly. What i am trying to do is to generate a lottery winning ticket and number. The comments ahead of each of my codes explains what i want to achieve there. I will appreciate if any expert in the house can help me look into my code and make adjustments on it and put comments as to why the adjustment was made. this will help me undertsand my errors. I am a vba learner.
Thanks All.
Dim WinningNumb As String
Dim X As Integer
Dim J As Integer
Dim Tickets As String
Dim TicketNumb As String
' Generate the winning number as a sequence of digits from 0 to 9.
For X = 1 To 100
WinningNumb = ""
For J = 0 To 9
WinningNumb = WinningNumb & Int(Rnd * 5)
Next
' Find how many cards user wants to buy and redim the array to the proper size.
TicketNumb = 0
' Generate the tickets and store them in the array
Do
TicketNumb = TicketNumb + 1
Tickets = ""
' Look for a winner by comparing the winning number to the contents of the array
For J = 0 To 9
Tickets = Tickets & Int(Rnd * 5)
Next
Loop Until Tickets = WinningNumb
' Report the result in a message box
MsgBox "The Winning Ticket is " & "Tickets" & vbCrLf & " The Winning Lottery Number is " & "WinningNumb"
Next
End Sub
Thanks All.
Dim WinningNumb As String
Dim X As Integer
Dim J As Integer
Dim Tickets As String
Dim TicketNumb As String
' Generate the winning number as a sequence of digits from 0 to 9.
For X = 1 To 100
WinningNumb = ""
For J = 0 To 9
WinningNumb = WinningNumb & Int(Rnd * 5)
Next
' Find how many cards user wants to buy and redim the array to the proper size.
TicketNumb = 0
' Generate the tickets and store them in the array
Do
TicketNumb = TicketNumb + 1
Tickets = ""
' Look for a winner by comparing the winning number to the contents of the array
For J = 0 To 9
Tickets = Tickets & Int(Rnd * 5)
Next
Loop Until Tickets = WinningNumb
' Report the result in a message box
MsgBox "The Winning Ticket is " & "Tickets" & vbCrLf & " The Winning Lottery Number is " & "WinningNumb"
Next
End Sub