|
-
March 15th, 2001, 12:03 PM
#1
Need help with optional function parameters!
I have a function that takes a list of 4 parameters. Only 1 of these are needed and the function executes differently depending on the other 3 parameters. ie:
If parameter2<>"" then
do this
end if
if parameter3<>"" then
do this
end if
and so on...but when i call the function:
MyFunction(1,,"hello")
I get an error saying Parameter2 doesn't exist. How can i check to see if parameter2 has a value? I tried isNull and that didn't work either. Thanks for your help!
-Aaron
-
March 15th, 2001, 12:08 PM
#2
Re: Need help with optional function parameters!
In your function type the word 'Optional' in fromt of your optional parameter
Iouri Boutchkine
[email protected]
-
March 15th, 2001, 12:14 PM
#3
Re: Need help with optional function parameters!
I do that but I still get the error (sorry, i should have mentioned that)
-Aaron
-
March 15th, 2001, 12:15 PM
#4
Re: Need help with optional function parameters!
There are two methods to it. If it doesn't matter if the arguments are variant, then you can use the IsMissing() function to check if the parameter was passed.
private Sub Func1(Param1, optional Param2, optional Param3, optional Param4)
If Not IsMissing(Param2) then
...
...
End If
... and so on
End Sub
If instead, your variable cannot be variant, you can set it in the declaration to a value that the variable doesn't typically contain as follows. Then in the function, check if the variable has that atypical value.
private Sub Func2(Param1 as Integer, optional Param2 as Integer = -999, optional Param3 as string = "", optional Param4 as Boolean = true)
If Not (Param2 = -999) then
...
...
End If
... and so on
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|