In the form declaration section
Dim Output As String
Dim Rangeone As String ' Lowest number to randomize
Dim Rangetwo As String 'Highest number to randomize
Dim Picks As String 'How many seperate rows of numbers is displayed
Dim Plays As String 'How many numbers per row are displayed
Dim Rand1 As System.Random
Dim arrNumbers(1, 1) As Boolean
In the Button_Click event
Rangeone = TextBox2.Text 'lowest number permitted
Rangetwo = TextBox3.Text 'highest number permitted
Picks = TextBox5.Text 'number of numbers per line
Plays = TextBox4.Text 'number of lines required
ReDim arrNumbers(Val(Rangetwo) - Val(Rangeone) + 1, 1)
If Val(Plays) = 0 Or Val(Plays) > 3 Then 'this puts a limit
on the maximum
number of Plays.
MsgBox("You must enter the CORRECT number of Plays")
Exit Sub
Else
Rand1 = New Random(Now.Millisecond) 'sets random generator in motion
CalculateNumbers() 'calls number generation Sub
End If
New Sub
Private Sub CalculateNumbers()
Dim iCount, iCount1, iCount2 As Integer
For iCount = 1 To Val(Plays) 'controls number of lines requested
For iCount1 = 1 To Val(Picks) 'controls number of selections per line
Do
Output = Str(Rand1.Next(Val(Rangeone), Val(Rangetwo))) 'selects next random number
If arrNumbers((Val(Output) - Val(Rangeone)), 0) = True Then
MessageBox.Show(Output & "Duplicated")
Else
arrNumbers(Val(Output) - Val(Rangeone) + 1, 0) = True 'stores TRUE in selected number line of array
Exit Do
End If
Loop
Next
'arrNumbers will now have the required number of numbers for one line
'insert code to store them in the Picks listbox or whatever you are using.
' to do this iterate through arrNumbers checking for those which are set to TRUE
For iCount2 = 0 To Val(Rangetwo) 're-set array
If arrNumbers(iCount2, 0) = True Then
arrNumbers(iCount2, 0) = False
End If
Next
Next
End Sub