Passing multiple variables through functions

X

Xiazer

I can successfully pass at least one variable to a function but I cannot
pass multiple for the life of me. here is an example

something simple like trying to send a box to hide a group of 2 buttons
as visible

Private Sub cmdHideButtons_Click()
hidegrp(cmdButton1.visible, cmdButton2.visible)

End Sub

Function hidegrp(Value1 as Boolean, Value2 as Boolean)
Value1 = False
Value2 = False

End Function


Now this function Wont work, but i just wanted to illistrate the
principle of passing 2 variables. now if I did it with just one
variable it works fine, other wise it gives me an error *Compile error
: Expected: =*. All i want to know is why it does this and is there a
way around it
 
B

Bob Phillips

Xiazer said:
I can successfully pass at least one variable to a function but I cannot
pass multiple for the life of me. here is an example

something simple like trying to send a box to hide a group of 2 buttons
as visible

Private Sub cmdHideButtons_Click()
hidegrp(cmdButton1.visible, cmdButton2.visible)

End Sub

Function hidegrp(Value1 as Boolean, Value2 as Boolean)
Value1 = False
Value2 = False

End Function


Now this function Wont work, but i just wanted to illistrate the
principle of passing 2 variables. now if I did it with just one
variable it works fine, other wise it gives me an error *Compile error
: Expected: =*. All i want to know is why it does this and is there a
way around it
You don't need th brackets

Private Sub cmdHideButtons_Click()
hidegrp cmdButton1.visible, cmdButton2.visible
End Sub
 
L

Lucas Swanson

A couple of things:

Firstly, since you are not returning any value with your hidegrp procedure
it would be better to make it a "Sub" rather than a "Function"

Sub HideGrp(Value1 as Boolean, Value2 as Boolean)

Secondly, the problem is in the calling of the function, rather than the
definition of it and is thanks to a peculiarity in VBA formatting. It does
not particularly like parentheses for some reason. Anyways, either of the
following should work for you: leaving out the parentheses or using the
"Call" keyword. I prefer using Call as I find it less ambiguous.

Private Sub cmdHideButtons_Click()
call hidegrp(cmdButton1.visible, cmdButton2.visible)
End Sub
 

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

Top