Cannot use parentheses when calling a Sub

E

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?
 
T

Tim Slattery

Excel User said:
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.
 
E

Evertjan.

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
 
D

Daniel Crichton

Excel wrote on Fri, 26 Jun 2009 20:42:06 +0100:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top