S
Sangeetha
Hi,
I am newbie. I want a report as a output which will generate a random
numbers and the user to will input the number of records to be selected and
the range 9top value and the bottom value).
i copied the below module and entered in a new database, which does not have
any forms, tables or reports. it perfectly works. But, i want the same to be
displayed on a report. Also, the user should supply variables for hi value ,
liw value and the number of records to eb selected. pleas help. Urgent.
Thanks.
Function testGetRandom()
' test getRandomNumbers function
Const lo = 0 ' Low boundary of population
Const hi = 500 ' High boundary of population
Const itms = 30 ' Number of items to return
Dim X As Variant
X = getRandomNumbers(lo, hi, itms)
Dim i As Integer
For i = lo To hi
If X(i) = True Then Debug.Print i
Next i
End Function
Function getRandomNumbers(lo As Integer, hi As Integer, toSelect As Integer)
' Purpose:
' Return an indicated number of unique random numbers from
' a defined population.
' In:
' lo The bottom number in the population
' hi The top number in the population
' e.g: lo = 73, hi = 250
' toSelect The number of items between lo & hi to return.
' Out:
' Variant array of booleans
' If the item is selected item(i) = True
' If the item isn't selected item(i) = False
' Created:
' mgf 25may99
ReDim items(lo To hi) As Variant
Dim selected As Integer
' Seed the randomizer
Randomize
' Generate the array of unique, random items
Do While selected < toSelect
Dim rec As Integer
' Get a number between lo and the hi boundaries
' *From the VBA Help file on Rnd()*
rec = Int((hi - lo + 1) * Rnd + lo)
' If the item hasn't been marked, mark it.
If items(rec) = False Then
items(rec) = True
' Keep track of the number of items selected.
selected = selected + 1
End If
Loop
getRandomNumbers = items
End Function
I am newbie. I want a report as a output which will generate a random
numbers and the user to will input the number of records to be selected and
the range 9top value and the bottom value).
i copied the below module and entered in a new database, which does not have
any forms, tables or reports. it perfectly works. But, i want the same to be
displayed on a report. Also, the user should supply variables for hi value ,
liw value and the number of records to eb selected. pleas help. Urgent.
Thanks.
Function testGetRandom()
' test getRandomNumbers function
Const lo = 0 ' Low boundary of population
Const hi = 500 ' High boundary of population
Const itms = 30 ' Number of items to return
Dim X As Variant
X = getRandomNumbers(lo, hi, itms)
Dim i As Integer
For i = lo To hi
If X(i) = True Then Debug.Print i
Next i
End Function
Function getRandomNumbers(lo As Integer, hi As Integer, toSelect As Integer)
' Purpose:
' Return an indicated number of unique random numbers from
' a defined population.
' In:
' lo The bottom number in the population
' hi The top number in the population
' e.g: lo = 73, hi = 250
' toSelect The number of items between lo & hi to return.
' Out:
' Variant array of booleans
' If the item is selected item(i) = True
' If the item isn't selected item(i) = False
' Created:
' mgf 25may99
ReDim items(lo To hi) As Variant
Dim selected As Integer
' Seed the randomizer
Randomize
' Generate the array of unique, random items
Do While selected < toSelect
Dim rec As Integer
' Get a number between lo and the hi boundaries
' *From the VBA Help file on Rnd()*
rec = Int((hi - lo + 1) * Rnd + lo)
' If the item hasn't been marked, mark it.
If items(rec) = False Then
items(rec) = True
' Keep track of the number of items selected.
selected = selected + 1
End If
Loop
getRandomNumbers = items
End Function