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

Looping??

Status
Not open for further replies.

hummer010

Technical User
Sep 29, 2000
12
0
0
CA
To start off, I know nothing about VBscript. I am using instructions I found on the internet, and trying to adapt them to my needs. I am writing a couple of asp's for database access from the web. I need to have a looping function from a user entered number to a user entered number. I currently have this:

do while From_Twp != To_Twp

-- Function --

From_Twp = From_Twp + 1
loop

Those of you who know vbscript probably are thinking " Of course it doesn't work" When I try to run it I get a VBscript error "Expected Statement" If you guys can tell me how to make this loop run that would be great!!

P.S. Sorry for the long post. [sig][/sig]
 
Hi,

Dim From_Twp,To_Twp

From_Twp=1
To_Twp=10

do while From_Twp <> To_Twp
From_Twp=From_Twp+1
loop

vb script uses <> instead of !=

Regards, [sig]<p>Russ<br><a href=mailto:bobbitts@hotmail.com>bobbitts@hotmail.com</a><br><a href= is in</a><br>[/sig]
 
Okay, changing the != to a <> made the script work, but the loop is never ending!! I take the From_Twp and To_Twp froma Querystring. From_Twp is always smaller than To_Twp. If I run the loop with <>, it is a never ending loop. If replace the <> with a simple <, it is still a never ending loop, why won't the loop stop. Here is an example of a simple loop I am trying:

<%@ Language = VBscript %>
<%

'Declare Variables

Dim From_Twp
Dim To_Twp

'Grab Variables from Querystring

From_Twp=Request.Querystring(&quot;From_Twp&quot;)
To_Twp=Request.Querystring(&quot;To_Twp&quot;)

do while From_Twp < To_Twp

response.write(From_Twp)

From_Twp=From_Twp+1

loop
%>

Now if, for example, I entered From_Twp=12 and To_Twp=18 I should get a blank screen with the followin line at the top: 121314151617. Unfortunately this doesn't happen, the line keeps growing and growing. Why does the loop keep going when From_Twp is greatere than To_Twp?? [sig][/sig]
 
I'm not familiar with ASP (so maybe there's something obvious here that I'm missing -- those savvy to ASP, please butt in if this is the case), but as far as I can tell the syntax of your code looks fine. Are you sure that the values of your query strings are what you think they are? Try Doing this and see if it works:

<%@ Language = VBscript %>
<%

'Declare Variables

Dim From_Twp
Dim To_Twp

'Grab Variables from Querystring

From_Twp=12
To_Twp=18
do while From_Twp < To_Twp

response.write(From_Twp)

From_Twp=From_Twp+1

loop
%>

If it does, take a look at the values your getting from the query string:

<%@ Language = VBscript %>
<%

'Declare Variables

Dim From_Twp
Dim To_Twp

'Grab Variables from Querystring

From_Twp=Request.Querystring(&quot;From_Twp&quot;)
To_Twp=Request.Querystring(&quot;To_Twp&quot;)

MsgBox(&quot;From_Twp: &quot; & From_Twp)
MsgBox(&quot;To_Twp: &quot; & To_Twp)

do while From_Twp < To_Twp

response.write(From_Twp)

From_Twp=From_Twp+1

loop
%>

Regards, [sig]<p>Russ<br><a href=mailto:bobbitts@hotmail.com>bobbitts@hotmail.com</a><br><a href= is in</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top