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 variable to sub not working

Status
Not open for further replies.

tractorvix

Technical User
Jun 29, 2004
122
0
0
GB
Hi all,

I'm sure I'm missing something really simple here, but it's absolutely foxing me.

I'm trying to pass a couple of values to a function to give me the option of looping. It works fine if I pass one string using the following:

Private Function SendMsg(msg As String)
MsgBox msg
End Function

Private Sub Command0_Click()
Sendmsg ("This is a test")
End Sub


But when I amend the function to 2 inputs:
Private Function SendMsg(msg As String, title As String)
MsgBox msg,,Title
End Function

and update the Command0_Click to:
Private Sub Command0_Click()
Sendmsg ("This is a test", "This is a title")
End Sub

I get a compile error 'Expected:="

I've tried MS help, but it's really not that useful!

Thanks
Vicky
 
Replace this:
Sendmsg ("This is a test", "This is a title")
with either this:
Call Sendmsg ("This is a test", "This is a title")
or this:
Sendmsg "This is a test", "This is a title"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Buried in the the helpfile, here is why.

You are not required to use the Call keyword when calling a procedure.
1)However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses.

2)If you omit the Call keyword, you also must omit the parentheses around argumentlist.

3)If you use either Call syntax to call any intrinsic or user-defined function, the function's return value is discarded.
 
I suspected it would be something ridiculous simple that I was missing.

Thanks for your help guys.

Vicky
 
And why is it a Function rather than a Sub?

You are not returning anything for the Function Name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top