help with parameter not passed from for loop to while loop

P

pauljturner99

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?
 
B

Bob Barrows [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top