
November 29th, 2003, 12:54 PM
|
 |
Inherits Programmer.Slacker
|
|
Join Date: Aug 2003
Location: Between my Id and your Ego
|
|
personally, I would use the number of records in the table as the upper bound of the Rnd() function to generate a random number. Something like this maybe...
Code:
'assume rsRecordset and cnConnection already declared
Private Sub Form_Load()
Dim CurrStudent As Integer
Dim intStudents() As Integer
Dim Upperbound As Integer
Dim blnInArray As Boolean
Dim intI As Integer, intJ As Integer
Dim NumRequiredStudents As Integer
Upperbound = (rsRecordset.recordcount - 1)
'assign numrequired students to exact number needed (1-based)
For intJ = 0 To NumRequiredStudents - 1
CurrStudent = CInt((Upperbound * Rnd) + 0)
For intI = 0 To UBound(intStudents)
If intStudents(i) = CurrStudent Then
blnInArray = True
Else
blnInArray = False
End If
Next intI
If blnInArray = False Then
ReDim Preserve intStudents(UBound(intStudents) + 1)
intStudents(UBound(intStudents)) = CurrStudent
Else
intJ = intJ - 1
End If
Next intJ
End Sub
I haven't field tested this yet, so it may need a little tweaking
__________________
Fisherman
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein
|