function not functioning in a loop

Discussion in 'ASP General' started by Mike, Sep 25, 2003.

  1. Mike

    Mike Guest

    This may be stupid but


    Function TestFunction(strValue)
    TestFunction = strValue + 1
    End Function

    y = 1

    For x = 1 to 10
    Response.write TestFunction(y) & "<br>"
    y = y + 1
    Next

    produces
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    Shouldn't it produce

    2
    4
    6
    etc.

    It seems like the function is only running the first time through the loop.
    What am I missing?

    Thanks
    Mike
    Mike, Sep 25, 2003
    #1
    1. Advertising

  2. Mike

    PB4FUN Guest

    Re: function not functioning in a loop -> this works

    You are not changing the variable y
    In the function you should add a line to increase the value of y

    This will work

    Function TestFunction(strValue)
    TestFunction = strValue + 1
    strValue = strValue +1
    End Function

    It produces
    2
    4
    6 etc

    If you want to have 3 5 7 etc you should increase the value of y before you
    set TestFunction = strValue + 1

    Meindert, MCP

    "Mike" <> wrote in message
    news:#...
    > This may be stupid but
    >
    >
    > Function TestFunction(strValue)
    > TestFunction = strValue + 1
    > End Function
    >
    > y = 1
    >
    > For x = 1 to 10
    > Response.write TestFunction(y) & "<br>"
    > y = y + 1
    > Next
    >
    > produces
    > 2
    > 3
    > 4
    > 5
    > 6
    > 7
    > 8
    > 9
    > 10
    > 11
    >
    > Shouldn't it produce
    >
    > 2
    > 4
    > 6
    > etc.
    >
    > It seems like the function is only running the first time through the

    loop.
    > What am I missing?
    >
    > Thanks
    > Mike
    >
    >
    >
    PB4FUN, Sep 25, 2003
    #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. sadf
    Replies:
    4
    Views:
    806
    Bob Carsto
    Nov 14, 2003
  2. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    Enable property of a Panel not functioning

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Feb 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    348
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Feb 7, 2005
  3. surveyor04
    Replies:
    0
    Views:
    367
    surveyor04
    Feb 12, 2005
  4. Mike

    function not functioning in a loop

    Mike, Sep 25, 2003, in forum: ASP General
    Replies:
    10
    Views:
    199
  5. Isaac Won
    Replies:
    9
    Views:
    354
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page