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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random numbers timing out

Status
Not open for further replies.

penguinspeaks

Technical User
Nov 13, 2002
234
US
Here is my code

Code:
Dim my_num,max,min

max=cint(vcnt2)
min=1
x = 1
do while x < max+1
Randomize
my_num=int((max-min+1)*rnd+min)

	set chk1 = conn.execute("select * from bracket_ where t_id = "&t_id&" and pos_ = "&my_num&"")
	if chk1.eof then
	strSQL = "update bracket_ set pos_ = "&my_num&" where team_id = '"&x&"'"
    conn.execute (strSQL)
    x=x+1
    else
    end if

loop

In theory, this should check against the database table to see if the value has been entered, if not, enter it, and if so, go back to the loop. THe first time I tested this, it worked fine. Every time I have tested after this, it keeps timing out.
the vcnt2 variable is a count of players in the table.

Can anyone see why this would time out? For the example I have shown, it is only 8 for the max
 
I changed the select * to just select pos_ but I am still having issues.

I have no clue on this one.

If I take out the lookup part, and just create random numbers, it runs fine but I get duplicates.
 
Hmm, do I need to define x again if it the random number is found?

if .....
x=x+1
else
x=x
end if


something to that regards?
 
Using your example where max = 8...

Your loop never ends because the only way out of the loop is:
a) X needs to be incremented until it's higher than 8
b) X only gets incremented if the random# is NOT already in the "pos_" field.

In other words, if the numbers 1 through 8 are all in the "pos_" field somewhere in "bracket_" table, your loop will never exit.

I really can't help further, as I dont quite understand what you are trying to accomplish. A start would be to pull the x=x+1 outside the if statement, so X gets incremented each pass through the loop

Code:
do while x < max+1
   ...
   if chk1.eof then
      strSQL = ...
      conn.execute (strSQL)
   else
   end if
   x=x+1
loop
 
Randomize should be outside the loop

x only increments when check1.eof is true. If you never hit eof, it never increments.

If you want to run the operation max times, use a for loop instead of a while loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top