ASP - Creating a custom function

Discussion in 'HTML' started by Noozer, Sep 26, 2004.

  1. Noozer

    Noozer Guest

    Having a bad day here..

    I need to create a custom function in an ASP page... (and please let me know
    if there's a better group to ask in)

    Since ASP does not have a MAIN funtion or LOAD event, code just starts at
    the first ASP statement... so where do I define a custom function? How do I
    return a value from a function?

    This is what I'd like to add...

    function toNum(val)
    if ISNUMERIC(val) THEN
    return cint(val)
    else return 0
    end if
    end function
    Noozer, Sep 26, 2004
    #1
    1. Advertising

  2. Noozer

    Noozer Guest

    > I need to create a custom function in an ASP page... (and please let me
    know
    > if there's a better group to ask in)


    I forgot... It works like VB. This code seems to do the trick:

    function toNum(val)
    IF ISNUMERIC(val) THEN
    toNum = cint(val)
    else
    toNum = 0
    end if
    end function

    Just stuck it after the </BODY> tag - but I'm sure that there's a better
    place to put it.
    Noozer, Sep 26, 2004
    #2
    1. Advertising

  3. *Noozer* wrote in alt.html:

    [Follow-up set to microsoft.public.inetserver.asp.general]

    > Having a bad day here..
    >
    > I need to create a custom function in an ASP page... (and please let me know
    > if there's a better group to ask in)


    news:microsoft.public.inetserver.asp.general

    > Since ASP does not have a MAIN funtion


    ASP is not a language, it's an API to the webserver (usually IIS).

    > or LOAD event, code just starts at the first ASP statement... so where
    > do I define a custom function?


    It might seem obtuse, but you can define a function anywhere you like.
    Although the usual method is to put functions into separate files and
    include them at the top of the page using SSI syntax - the idea being to
    attempt to separate script from markup for clarity and ease of
    maintenance.

    > How do I return a value from a function?


    It depends on the language you use under ASP (VBScript, JScript,
    Perlscript, ...)

    > This is what I'd like to add...
    > function toNum(val)
    > if ISNUMERIC(val) THEN
    > return cint(val)
    > else return 0
    > end if
    > end function


    Looks like VBScript and I'm not really familiar with it, instead here's
    an approximation in JScript with some assumptions:

    <%@language="JScript"%>
    <%
    function toNum(val) {
    if (isNaN(val)) {
    return 0;
    }
    else {
    return Math.floor(val);
    }
    }
    %>

    ....
    <h1>Test</h1>
    <p>My test result is <%=toNum(57.5)%></p>
    ....


    Don't forget the follow-up...
    --
    Andrew Urquhart
    - FAQ: http://www.html-faq.com/
    - Archive: http://groups.google.com/groups?group=alt.html
    - Contact me: http://andrewu.co.uk/contact/
    Andrew Urquhart, Sep 26, 2004
    #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. Replies:
    1
    Views:
    554
    Juan T. Llibre
    May 18, 2005
  2. Ravi Ambros Wallau
    Replies:
    0
    Views:
    4,090
    Ravi Ambros Wallau
    Jun 1, 2005
  3. Alexandre Guimond

    creating custom options for custom widgets?

    Alexandre Guimond, Mar 22, 2006, in forum: Python
    Replies:
    0
    Views:
    371
    Alexandre Guimond
    Mar 22, 2006
  4. Garrett Cooper

    Creating custom formatter function

    Garrett Cooper, Feb 16, 2009, in forum: Python
    Replies:
    1
    Views:
    330
    Alan G Isaac
    Feb 16, 2009
  5. Ravi Ambros Wallau
    Replies:
    0
    Views:
    310
    Ravi Ambros Wallau
    Jun 1, 2005
Loading...

Share This Page