Here is the situation: Im tyring to create a page that will select 150 random winners and mark them. Simple enough... Let me explain the details...
The table, 'lottery', has an id, and a winner(boolean field). When people apply they get added with false as the winner field. Now, when the user wants, I need to select 150 random winners.
Here is the code I used
dim intWinners, intUBound, intLBound, intRec
intWinners = 150
'Generate the winners
dim objLotWinners
set objLotWinners = Server.CreateObject("ADODB.Recordset")
strQuery = "select * from lottery where allt(class)='SR' and winner=.f."
objLotWinners.open strQuery, objWebHRSConn, adOpenKeyset, adLockOptimistic
intUBound = objLotWinners.recordcount - 1
intLbound = 0
i = 1
do while i <= intWinners
'pick a random number between 1 and the number of potentinal winners
'goto that record and mark it
randomize
intRec = Int((intUBound - intLBound + 1) * Rnd + intLBound)
objLotWinners.move intRec, adBookmarkFirst
if not objLotWinners("winner") then
objLotWinners("winner") = True
objLotWinners.update
i = i + 1
end if
loop
'WebHRS is my connection object
Now my problem...
Whenever the random number repeats, it crashes. As if the update isnt updating. I printed teh value of the field before and after the update and they were what they were supposed to be. But when it moved to a different record and then moved back, winner was false again. Also, some other wierd stuff happens. If a the random number is the same right after the other it will skip it, like it is supposed to, and not crash. It will only crash if a random number comes up again 2 or more numbers down the line. So whats going on?
Any suggestions on the problem? Or is there some other way I can do this? I have though of just creating another table and copying the winner records into it, but now that this problem has arisen I want to solve it :)
Thanks in advance,
Eric
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only