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

Looping question - problem

Status
Not open for further replies.
Nov 29, 2002
64
US
Hello there, I need your help before I [pc]...

A part of my result table should show 1, 2, 3 .. rows (never more than 10) depending on the value entered by the user through a form.
The output must be, if the user enters 4:

some info
1º Item
2º Item
3º Item
4º Item
other info

The code I have now looks like:
Code:
<% form_nritems=request.form("nritems")  %>

<% i= 1
   do until i = form_nritems   
   'also tried with do while i < form_nritems
%>
<tr>   	 
   <td><%= i%>º Item</td>
</tr>
 <% i = i + 1
 loop
 %>

The issue is that with this code my page seem to enter in a neverending bucle, killing all the resources on my machine, like if it never finds the form_nritems value. But, [curse], if I do:

Code:
<% form_nritems=request.form("nritems")  %>
<% 
   i= form_nritems
   do until i = 0
    %>
<tr>   	 
   <td><%= i%>º Item</td>
</tr>
 <% i = i - 1
 loop
 %>

it works perfect and brings the results in a second!!! But of course, reverse way, which doesn't work for my users... What am I doing wrong with the first code??? Any ideas, workarounds???

(I've also tried:
i= form_nritems
x= 1
do while x < i with no luck....)
thanks!
Alfredo
 
this section really catches my eye

do until i = form_nritems

are you certain that form_nitems is a int? It just seems far to likly to get caught there due to the comparison.

I would absolutely before going any farther test that form_nitems value for accuracy

e.g.
form_nritems = request.form("nritems")
If IsNumeric(form_nitems) Then
.. loop ..
Else
.. you have problems
End If

or even a slight check of
form_nitems > 0

___________________________________________________________________

The answer to your ??'s may be closer then you think. faq333-3811
Join the Northern Illinois/Southern Wisconsin members in Forum1064
 
you could try forcing your value to an Integer before using it in your loop...
Code:
<% form_nritems = CInt(Request.Form("nritems"))%>

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
The only thing about this
form_nritems = CInt(Request.Form("nritems"))%

If it is not a numeric value it will error out I believe.

watch yourself there unless the entry is hard cdoed and not user dependant

___________________________________________________________________

The answer to your ??'s may be closer then you think. faq333-3811
Join the Northern Illinois/Southern Wisconsin members in Forum1064
 
Does this work:

<% form_nritems=request.form("nritems") %>

<% i= 1
j=form_nritems
do until i = j
'also tried with do while i < form_nritems
%>
<tr>
<td><%= i%>º Item</td>
</tr>
<% i = i + 1
loop
%>

-VJ
 
Yes... CInt() or CLng() should help. Request values are strings and that causes infinite loop.

Btw. why not using For... Next?
 
Thanks to all of you. Of course the CInt fixed the problem.
[hammer] Ok, I'm going back to bed, it's clear I'm still asleep.

hey vongrunt, why For and not Do? Is it really a difference?

thanks!
alfredo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top