Returning a value from a function

Discussion in 'ASP General' started by neptune6644@gmail.com, Sep 29, 2006.

  1. Guest

    I'm having trouble getting the following function to return a value,
    unless I add a response.write to the end of the function. Calling the
    function will not get the value to appear.

    <%

    Dim strMyVar1, strMyVar2, poop

    strMyVar1 = 75.5
    strMyVar2 = 5.5

    '----------------------------------------------------------------------------------------
    'Why isn't this displaying a returned value?!?
    '----------------------------------------------------------------------------------------
    Response.Write per_to_dec(strMyVar1) & "<br>"


    FUNCTION per_to_dec(poop)

    if len(poop) = 1 then
    poop = ".0" & strPer_to_Dec
    end if

    'ex. 47%
    if len(poop) = 2 then
    poop = "." & poop
    end if

    'ex 1.5%
    if len(poop) = 3 AND mid(poop,2,1) = "." then
    poop = Replace(poop,".","")
    poop = ".0" & poop
    end if

    'ex. 1.75% or 17.5%
    if len(poop) = 4 then
    if mid(poop,2,1) = "." then
    poop = Replace(poop,".","")
    poop = ".0" & poop
    elseif mid(poop,3,1) = "." then
    poop = Replace(poop,".","")
    poop = "." & poop
    end if
    end if

    'ex. 10.75%
    if len(poop) = 5 then
    poop = Replace(poop,".","")
    poop = "." & poop
    end if


    '----------------------------------------------------------------------------------------
    'This is the only way this function will display a returned value

    '----------------------------------------------------------------------------------------
    response.write poop
    END FUNCTION
    %>

    What am I doing wrong?

    Thanks.
    , Sep 29, 2006
    #1
    1. Advertising

  2. McKirahan Guest

    <> wrote in message
    news:...
    > I'm having trouble getting the following function to return a value,
    > unless I add a response.write to the end of the function. Calling the
    > function will not get the value to appear.


    [snip]

    You have to set the name of the Function to your return value
    before "End Function":

    per_to_dec = poop
    McKirahan, Sep 29, 2006
    #2
    1. Advertising

  3. Guest

    McKirahan wrote:
    > <> wrote in message
    > news:...
    > > I'm having trouble getting the following function to return a value,
    > > unless I add a response.write to the end of the function. Calling the
    > > function will not get the value to appear.

    >
    > [snip]
    >
    > You have to set the name of the Function to your return value
    > before "End Function":
    >
    > per_to_dec = poop


    Yep! Thanks. Was just coming back to post a "nevermind." I finally saw
    what was wrong. it's been a loooooooooooooong day. hehe

    Thanks for the reply.
    , Sep 29, 2006
    #3
    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. darrel
    Replies:
    3
    Views:
    723
    darrel
    Aug 6, 2004
  2. Jochen Zeischka

    void function returning value?

    Jochen Zeischka, Feb 25, 2004, in forum: C++
    Replies:
    3
    Views:
    5,151
    John Harrison
    Feb 25, 2004
  3. shaun
    Replies:
    3
    Views:
    448
    shaun
    Apr 19, 2005
  4. Joe Wright

    returning a floating point value from a function

    Joe Wright, Jun 5, 2004, in forum: C Programming
    Replies:
    12
    Views:
    580
    geowar
    Dec 10, 2004
  5. Replies:
    11
    Views:
    662
    Christos Georgiou
    May 2, 2006
Loading...

Share This Page