Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing variables in a function

Status
Not open for further replies.

patchkit

IS-IT--Management
Nov 20, 2001
17
US
Wondering if anyone can point out what I may be doing wrong here.

'function code

Function passTwoValues(val1,val2)
Response.write val1
Response.write val2
end function

'call code

passTwoValues("abc","xyz")

I get this response:

Microsoft VBScript compilation (0x800A0414)
Cannot use parentheses when calling a Sub
/intranetredesign/index.asp, line 55, column 22
passTwoValues("abc","xyz")

If I just place in one variable like so:

passTwoValues("abc")

I get:

Wrong number of arguments or invalid property assignment: 'passtwovalues'

I am trying to pass a file name and a URL path, but since the easy code is not working I will wait to try the more complicated.

Thanks in advance,

Bill
 
Don't use parentheses when calling functions

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
ok, got it (feel rather dumb at the moment too :) ).

passTwoValues value1,value2

just seemed a little strange to me.
Thanks.
 
Or you could call the function:

Call passTwoValues(value1, Value2)

Look into this code snippet:

Code:
<%
            QS = Request.Querystring("ID")
            'Now pass the querystring to the following function.
            if QS = trim(aCategory(0, iRows)) then
               [b] Call GetProducts (CatID, Counter)[/b]
            end if
            %>
 
Rule of thumb is:
If your expecting a value back, use parantheses, otherwise don't.

Functions sometimes return values, so it's case by case
Sub's don't return values at all, so you don't use parantheses

-T

 
since you are trying to use as a function and using Tarwn's suggested rule of thumb ...

Code:
Function passTwoValues(val1,val2)
 passTwoValues = val1 & " " & val2
end function

Response.Write passTwoValues("Hello", "World")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top