I think this is what you might be looking for....
I'm kind of new to this forum so I'm not sure how this code is going to show in my posting...
You will need to create a form called Form1 with a label called Label1 - remove the Caption of this Label1 in the properties window.
Below is the code for the following subs called Main, Run_Random, and a Function called fncAlreadySelected.
I've tried to comment as much as possible. I'm fairly new to programming so if this doesn't do it for you (I've run it and it seems fine) there are a lot of capable people here that I'm sure could help.
Good luck....Are you trying to simulate a lottery game of some sort? (Just curious!!)
Code:
Option Base 1
Dim arrayNumbers(37) As Integer ' declare array
Dim arrayTenNos(10) As Integer ' array for checking if random #s repeat in group of 10
Sub Main()
Form1.Show
' fill array
For intList = 1 To 37
arrayNumbers(intList) = intList
Next intList
' run the 5 groups
For intFiveGroups = 1 To 5
' calls sub that generates random number & prints to label caption
Call Run_Random
' return to separate group
Form1.Label1.Caption = Form1.Label1.Caption & Chr(13)
' clears contents of arrayTenNos -- sets all values = 0
Erase arrayTenNos
Next intFiveGroups
End Sub
Sub Run_Random()
Dim intTenNumbers As Integer ' counter for 10 #s in the group
Dim intRandom As Integer ' random #
intTenNumbers = 1
Do
' Initializes the random-number generator.
Randomize
' generates random # from 1 to 37
intRandom = Int((37) * Rnd + 1)
' function that evaluates whether the # is already in group
If fncAlreadySelected(intRandom) = False Then
' if not in group already, assigns
arrayTenNos(intTenNumbers) = intRandom
' increased groups total count
intTenNumbers = intTenNumbers + 1
' post info to textbox
If intTenNumbers > 10 Then
' don't include hyphen after #
Form1.Label1.Caption = Form1.Label1.Caption & intRandom
Else
' do include hyphen after #
Form1.Label1.Caption = Form1.Label1.Caption & intRandom & "-"
End If
End If
Loop While intTenNumbers <= 10
End Sub
Function fncAlreadySelected(intRandom As Integer)
' function that evaluates whether or not _
the randomly generated # is already in the group
' loops thru arrayTerms elements
For x = 1 To UBound(arrayTenNos)
' If random # is same as # already in the group, _
set function to true, exit function
If arrayTenNos(x) = intRandom Then
fncAlreadySelected = True
Exit Function
End If ' If MyArray(x) > MyArray(x + 1) Then
Next x
' loop through group and found no redundant # so set fuction to false
fncAlreadySelected = False
End Function