INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

random numbers timing out

random numbers timing out

(OP)
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

RE: random numbers timing out

(OP)
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.

RE: random numbers timing out

(OP)
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?

RE: random numbers timing out

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 

RE: random numbers timing out

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close