Cannot use parentheses when calling a Sub

Discussion in 'ASP General' started by Excel User, Jun 26, 2009.

  1. Excel User

    Excel User Guest

    Hi,

    I have a function on a page:

    Function DisplayRelevantTable(val1,val2)

    'do something

    End Function


    and am calling this via:

    <%
    DisplayRelevantTable(Recordset1.Fields.Item("DateDraft").Value,Recordset1.Fields.Item("DateDraftlSent").Value)%>

    What am I doing wrong?
    Excel User, Jun 26, 2009
    #1
    1. Advertising

  2. Excel User

    Tim Slattery Guest

    "Excel User" <> wrote:

    >Hi,
    >
    >I have a function on a page:
    >
    >Function DisplayRelevantTable(val1,val2)
    >
    > 'do something
    >
    >End Function
    >
    >
    >and am calling this via:
    >
    ><%
    >DisplayRelevantTable(Recordset1.Fields.Item("DateDraft").Value,Recordset1.Fields.Item("DateDraftlSent").Value)%>


    It's a VB thing that's also in VBA and VBScript. When you call a
    function and don't retrieve the value, or if you call a function that
    has no return value, you cannot use parentheses. When you do catch the
    value, you MUST use parentheses. So:

    <%
    DisplayRelevantTable Recordset1.Fields.Item("DateDraft").Value,
    Recordset1.Fields.Item("DateDraftlSent").Value %>

    works.

    --
    Tim Slattery
    MS MVP(Shell/User)

    http://members.cox.net/slatteryt
    Tim Slattery, Jun 26, 2009
    #2
    1. Advertising

  3. Excel User

    Evertjan. Guest

    Tim Slattery wrote on 26 jun 2009 in
    microsoft.public.inetserver.asp.general:

    > It's [..] VBScript. When you call a
    > function and don't retrieve the value,
    > [..] you cannot use parentheses.


    UNLESS there is only one parameter,
    in which case the parentheses are
    only the outer wrapper of that parameter,
    so the parameter is resolved first.

    LEGAL:

    myFunction p1,p2,p3

    myFunction p1

    myFunction (p1)

    myFunction (p1),(p2),(p3)

    myFunction p1 + 75.9

    myFunction (p1 + 75.9) * 8

    ILLEGAL:

    myFunction (p1,p2,p3)

    LEGAL:

    myResult = myFunction (p1,p2,p3)

    ILLEGAL:

    myResult = myFunction p1,p2,p3

    myResult = myFunction (p1),(p2),(p3)

    ============================

    So, to prevent you from aquiring a bad habit,
    also do not use parentheses arount a single parameter.

    OR

    Always use parentheses and use the call statement

    LEGAL:

    call myFunction(p1,p2)

    ILLEGAL:

    call myFunction p1,p2


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jun 27, 2009
    #3
  4. Excel wrote on Fri, 26 Jun 2009 20:42:06 +0100:

    > Hi,


    > I have a function on a page:


    > Function DisplayRelevantTable(val1,val2)


    > 'do something


    > End Function



    > and am calling this via:


    > <% DisplayRelevantTable(Recordset1.Fields.Item("DateDraft").Value,
    > Recordset1.Fields.Item("DateDraftlSent").Value)%>


    > What am I doing wrong?


    Tim has already provided a workaround, here's another:

    Call DisplayRelevantTable(Recordset1.Fields.Item("DateDraft").Value,
    Recordset1.Fields.Item("DateDraftlSent").Value)

    and another

    vdummy = DisplayRelevantTable(Recordset1.Fields.Item("DateDraft").Value,
    Recordset1.Fields.Item("DateDraftlSent").Value)

    in the latter case the assignment of the output of the function (which is
    empty assuming that you don't set it in the function call) is assigned to a
    variable that isn't used for anything else.

    --
    Dan
    Daniel Crichton, Jun 30, 2009
    #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. Replies:
    7
    Views:
    9,193
    Jeff Dillon
    May 17, 2006
  2. Ben
    Replies:
    2
    Views:
    866
  3. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    1,979
    Lawrence D'Oliveiro
    May 20, 2011
  4. Richard Gration

    Legitimate use of calling a sub as &sub

    Richard Gration, Feb 23, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    111
    Brian McCauley
    Feb 23, 2005
  5. Martin Kissner

    Question about sub calling other sub

    Martin Kissner, Mar 4, 2006, in forum: Perl Misc
    Replies:
    8
    Views:
    98
    Martin Kissner
    Mar 9, 2006
Loading...

Share This Page