Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP General (http://www.velocityreviews.com/forums/f65-asp-general.html)
-   -   help with parameter not passed from for loop to while loop (http://www.velocityreviews.com/forums/t801659-help-with-parameter-not-passed-from-for-loop-to-while-loop.html)

pauljturner99@gmail.com 07-18-2006 11:56 PM

help with parameter not passed from for loop to while loop
 
Hi,

I'm trying to pass a parameter from a for loop to the nested while loop
but only the first counter is passed. Here is the code:

dim ctr
redim ctr(5)
ctr(0) = 2
ctr(1) = 4
ctr(2) = 6
ctr(3) = 8
ctr(4) = 10
ctr(5) = 12
dim counter
redim counter(5)
counter(0) = 0
counter(1) = 2
counter(2) = 2
counter(3) = 3
counter(4) = 4
counter(5) = 5

dim ctsum1
redim ctsum1(100)
dim ctsum2
redim ctsum2(100)
dim ctnoOut
redim ctnoOut(100)
dim ct
redim ct(100)
dim f1, f2
Dim re1, re2
dim sum1, sum2



If Not rs.EOF Then
for c = 0 to ubound(counter)
response.write "<tr><td>"
while Not rs.EOF
dim formtext, c1
formtext=(rs.fields.item(ctr(c)).value)

formtext is always 2 but I expect it to be 2, then 4, then 6 etc.. How
do I pass the counter from the for loop to while?


Bob Barrows [MVP] 07-19-2006 11:06 AM

Re: help with parameter not passed from for loop to while loop
 
pauljturner99@gmail.com wrote:
> Hi,
>
> I'm trying to pass a parameter from a for loop to the nested while
> loop but only the first counter is passed. Here is the code:
>
>
>
> If Not rs.EOF Then
> for c = 0 to ubound(counter)
> response.write "<tr><td>"
> while Not rs.EOF
> dim formtext, c1
> formtext=(rs.fields.item(ctr(c)).value)
>
> formtext is always 2 but I expect it to be 2, then 4, then 6 etc.. How
> do I pass the counter from the for loop to while?


First of all, it's not your problem, but don't declare (dim) formtext and c1
inside the loop. This is a bad practice. Variables should never be declared
inside a loop.
Also, use "Do While ... Loop" instead of the deprecated "While ... Wend"

"Pass" is not the correct terminology here. You "pass" arguments to methods.
This is simply a situation where an in-scope variable is used by a piece of
code. As to why the value assigned to formtext never changes, it's hard to
say without being able to debug your code. Your first step should be to
verify that c is incrementing the way you expect it to:

for c = 0 to ubound(counter)
Response.Write "c contains """ & c & """; "
Response.Write "ctr(c) contains """ & ctr(c) & """<BR>"
next

Once you have verified this, then work on the inner loop which you seem to
have snipped before we got to the interesting part.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"




All times are GMT. The time now is 10:49 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.