Using a function instead of a variable

Discussion in 'ASP General' started by seamlyne@hotmail.com, Jan 17, 2006.

  1. Guest

    Windows Server 2003, IIS 6, ASP Classic

    I need to do something like this:

    dim pageNum
    pageNum = request("page")
    if pageNum = "" then pageNum = 1

    ....and I need to do it several times. Another approach would be to do
    this:

    function fnPageNum
    fnPageNum = request("page")
    if fnPageNum = "" then fnPageNum = 1
    end function

    dim pageNum
    pageNum = fnPageNum

    In one method more efficient than the other, or do IIS not care either
    way?

    Bill in Kansas City
    , Jan 17, 2006
    #1
    1. Advertising

  2. wrote:
    > Windows Server 2003, IIS 6, ASP Classic
    >
    > I need to do something like this:
    >
    > dim pageNum
    > pageNum = request("page")
    > if pageNum = "" then pageNum = 1
    >
    > ...and I need to do it several times. Another approach would be to do
    > this:
    >
    > function fnPageNum
    > fnPageNum = request("page")
    > if fnPageNum = "" then fnPageNum = 1
    > end function
    >
    > dim pageNum
    > pageNum = fnPageNum
    >
    > In one method more efficient than the other, or do IIS not care either
    > way?
    >

    IIS does not care. For pure maintainability, I would use the function. The
    criterion is: never write the same sequence of code more than once. If it
    needs to be done more thaan once, encapsulate it in a sub or a function.

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Jan 17, 2006
    #2
    1. Advertising

  3. Use a generic function like this:-

    dim pageNum

    pageNum = GetRequestValue("page", 1)

    Function GetRequestValue(Name, Default)
    GetRequestValue = Request(Name)
    If GetRequestValue = Empty Then
    GetRequestValue = Default
    End If
    End Function


    "" wrote:

    > Windows Server 2003, IIS 6, ASP Classic
    >
    > I need to do something like this:
    >
    > dim pageNum
    > pageNum = request("page")
    > if pageNum = "" then pageNum = 1
    >
    > ....and I need to do it several times. Another approach would be to do
    > this:
    >
    > function fnPageNum
    > fnPageNum = request("page")
    > if fnPageNum = "" then fnPageNum = 1
    > end function
    >
    > dim pageNum
    > pageNum = fnPageNum
    >
    > In one method more efficient than the other, or do IIS not care either
    > way?
    >
    > Bill in Kansas City
    >
    >
    AnthonyWJones, Jan 17, 2006
    #3
  4. Guest

    That's sort of where I was to begin with, but I figured I'd ask.
    Ultimately, while I was waiting for the reply, that's what I did
    anyway. I have a rather large project, and it made sense.

    Thanks for taking the time!

    - Bill
    , Jan 18, 2006
    #4
    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. Jim Andersen
    Replies:
    3
    Views:
    4,330
    Jim Andersen
    Mar 2, 2006
  2. Brian
    Replies:
    2
    Views:
    323
    Brian
    Oct 31, 2003
  3. mfglinux
    Replies:
    11
    Views:
    670
    Roberto Bonvallet
    Sep 12, 2007
  4. AikidoGuy
    Replies:
    11
    Views:
    533
    Seebs
    Nov 21, 2011
  5. jackster the jackle
    Replies:
    2
    Views:
    92
    jackster the jackle
    Feb 7, 2008
Loading...

Share This Page