Home All Groups Group Topic Archive Search About

Cannot use parentheses when calling a Sub

Author
26 Jun 2009 7:42 PM
Excel User
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?

Author
26 Jun 2009 8:04 PM
Tim Slattery
Show quote Hide quote
"Excel User" <eu***@microsoft.com> 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)
Slatter***@bls.gov
http://members.cox.net/slatteryt
Are all your drivers up to date? click for free checkup

Author
30 Jun 2009 12:29 PM
Daniel Crichton
Excel wrote  on Fri, 26 Jun 2009 20:42:06 +0100:

Show quoteHide quote
> 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

Bookmark and Share