Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random records selection for contest

Status
Not open for further replies.

jasonsalas

IS-IT--Management
Jun 20, 2001
480
GU
Hi everyone,

I'm working on an online contest that will be database-driven with Access. The structure will be such that the DB app will be able to take a series of contestant entries, from a drop-down menu, and filter out the resultant recordset to include only those records where the correct choice was selected.

For example:
"SELECT * FROM tblContestants WHERE Response= '" & Tiger Woods "'"

At least that's the easy part. What I'd like to do is be able to have the app automatically select a record from the aforementioned extracted recordset AT RANDOM, and return only that. This will be the winning contestant for the week.

I'm hoping that the VBScript RANDOMIZE function is the best way to go about doing this. Do you know if the Randomize function can be applied towards a range of records? Because I won't know at design-time how many entries we'll have at any given time, I'm thinking I should write something like:

For i=0 to i -1

to iterate through the collection of winning records and then select a single.

Hmmm.....
 
You should use the getrows method

location=objRS.getrows 'You can dump your winner recordset into objRS and use the getrows method

Call Close 'You can call a sub to clsoe the recordset and database connection at this point.

numberrows=ubound(location,2) 'to get the total number of records

A random function can generate a random number between 0 to 1 if I remember correctly. Else just find out the range from the random function.
What I'll do is to divide the range, say 0 to 1 by the number of records, numberrows, say 33.
If the random number is 0.5, you multiply it by 33. It equals 16.5

Ignore all number after decimal places. Record number 16 will be the lucky record to be displayed.

So,

<% response.write location(0,Int(numberrows*Rnd))%> 'Say the first field of your record is the client name.

I'm not sure about the syntax of Int() and Rnd. Please correct me if I'm wrong.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top