I want to check an array to see if a random number that I am generating is already in the array. if the number is it will not add it to the array but if its not in the array it will add it to the array. the array I am talking about is named LottoNumbers and the code is below. currenty if adds all the random numbers to the array.
Newbie in search of knowledge
Code:
Dim LottoNumbers As Integer()
Dim intNum As Integer
Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
Dim number As Integer
Dim randomGenerator As New Random
ClearTextBoxes()
For num As Integer = 1 To 6
number = randomGenerator.Next(1, 49)
ReDim Preserve LottoNumbers(intNum)
LottoNumbers(intNum) = number
intNum += 1
If lblNum1.Text = "" Then
lblNum1.Text = number.ToString
ElseIf lblNum2.Text = "" Then
lblNum2.Text = number.ToString
ElseIf lblNum3.Text = "" Then
lblNum3.Text = number.ToString
ElseIf lblNum4.Text = "" Then
lblNum4.Text = number.ToString
ElseIf lblNum5.Text = "" Then
lblNum5.Text = number.ToString
ElseIf lblNum6.Text = "" Then
lblNum6.Text = number.ToString
End If
Next
End Sub
Private Sub ClearTextBoxes()
Dim ctrls As Control
For Each ctrls In Me.Controls
If TypeOf ctrls Is Label Then
ctrls.Text = ""
End If
Next
End Sub
Newbie in search of knowledge