help with parameter not passed from for loop to while loop

Discussion in 'ASP General' started by pauljturner99@gmail.com, Jul 19, 2006.

  1. Guest

    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?
     
    , Jul 19, 2006
    #1
    1. Advertising

  2. 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"
     
    Bob Barrows [MVP], Jul 19, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dee
    Replies:
    9
    Views:
    515
    Joseph Byrns
    Apr 15, 2005
  2. Steven

    while loop in a while loop

    Steven, Mar 24, 2005, in forum: Java
    Replies:
    5
    Views:
    2,241
    Tim Slattery
    Mar 30, 2005
  3. Uday Bidkar
    Replies:
    4
    Views:
    497
    =?ISO-8859-15?Q?Juli=E1n?= Albo
    Dec 12, 2006
  4. soren625
    Replies:
    10
    Views:
    240
    Kevin Collins
    Dec 28, 2005
  5. Isaac Won
    Replies:
    9
    Views:
    387
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page