I'm trying to create a random number generator (lottery). I have the random numbers generating, but I want to loop through the numbers that are checked in my CheckedListBox. It returns my last number checked, but not the others. Any suggestions?
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim number1 As Integer
Dim number2 As Integer
Dim number3 As Integer
Dim number4 As Integer
Dim number5 As Integer
Dim lottoPick As Integer = 0
Dim i As Integer
For i = 0 To LotteryBox.Items.Count - 1
If (LotteryBox.GetItemChecked(i) = True) Then
lottoPick = lottoPick + 1
LabelOutput.Text = (LotteryBox.Items(i))
End If
Randomize()
' The program will generate a number from 0 to 99
number1 = Int(Rnd() * 99) + 1
number2 = Int(Rnd() * 99) + 1
number3 = Int(Rnd() * 99) + 1
number4 = Int(Rnd() * 99) + 1
number5 = Int(Rnd() * 99) + 1
Next
LabelOutput.Text += number1.ToString() + " " + number2.ToString() + " " + number3.ToString() + " " + number4.ToString() + " " + number5.ToString()
End Sub
End Class
Aucun commentaire:
Enregistrer un commentaire