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

looping if statement

looping if statement

(OP)
I am trying to loop through records to see if a value exists. I can make it happen once, but how do I check while looping through the entire table?

CODE -->

con2 = (Int((max-min+1)*Rnd+min))

	set info5 = conn.execute("select confirm_ from orders where confirm_ = "&con2&"")
	if not info5.eof then
		
		max=9999999999
		min=1
		Randomize
		con2 = (Int((max-min+1)*Rnd+min))
		else
		con2 = con2
		end if 
Thanks

RE: looping if statement

Sorry, I don't follow your question, and your code seems incomplete. And you have no loop...

If you want a loop, use a Do While loop
http://ss64.com/vb/do.html

RE: looping if statement

(OP)
I didn't catch the loop and movenext while copying, my bad. This script checks the DB once for a duplicate. What I want it to do is if there is a duplicate, create another random number, and then check that one against the records. I need this to loop until there is not a duplicate.

Hope that makes sense.

RE: looping if statement

>I didn't catch the loop and movenext while copying, my bad.
OK. So post all of the loop this time, including the missing part, and we can see what needs to be corrected

RE: looping if statement

Well, something like this is what you are after

CODE

max=9999999999
min=1
Randomize

Dim bFound
bFound = False
Do While Not bFound
   con2 = (Int((max-min+1)*Rnd+min))
   set info5 = conn.execute("select confirm_ from orders where confirm_ = "&con2&"")
   if info5.eof then
      bFound = True
   end If
Loop 

RE: looping if statement

(OP)
Hello and thanks for your reply.

This continues to give me the exact number in the DB field. Here is what I have, as you have writen it:
[code}
Dim max,min
max=9999999999
min=1
Randomize

Dim bFound
bFound = False
Do While Not bFound
con2 = (Int((max-min+1)*Rnd+min))
set info5 = conn.execute("select confirm_ from orders where confirm_ = "&con2&"")
if info5.eof then
bFound = True
end If
Loop
[/code]

I do not see why this is not working properly.

RE: looping if statement

This continues to give me the exact number in the DB field
Sorry, I don't understand this sentence. What exact number is it giving you?

When the loop is done, con2 will be equal a value that is not already in the database, which is what you asked for. If it is NOT doing this, maybe you have "On Error Resume Next" which is suppressing error messages.

RE: looping if statement

(OP)
It gives the value of 2147483647 each time it runs.

RE: looping if statement

That is the expected behavior if you are not executing the "Randomize" command. Are you sure it's there in your code?

RE: looping if statement

(OP)
I posted the exact code.
The problem was the field setting in the DB.
It was set to INT and I do not believe that it can store a 9 digit number with that setting?

RE: looping if statement

Ahh, yes. 2147483647 is the maximum for that type. Use a different data type or use a smaller "max"

RE: looping if statement

(OP)
Thanks for the help. Now working great!

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