How to force an optional parameter to be missing (IsMissing returning True)? 
Author Message
 How to force an optional parameter to be missing (IsMissing returning True)?

How do I force an optional parameter to be missing without having to explicitly
miss it out from the call? (There are too many permutation in a 15 optional
parameter function to explicitly performs all possible call...)


Sun, 23 Nov 2003 21:51:43 GMT  
 How to force an optional parameter to be missing (IsMissing returning True)?

Quote:
>How do I force an optional parameter to be missing without having to
explicitly
>miss it out from the call? (There are too many permutation in a 15 optional
>parameter function to explicitly performs all possible call...)

My guess would be that it's be better to use typed parameters and have
default values that indicate "missing" but one way to do what you are asking
is like this:

Option Explicit

Private Sub Form_Load()
Dim vMissing As Variant
vMissing = GetMissing
Call MySub(vMissing)
Unload Me
End Sub

Private Sub MySub(Optional MyVar As Variant)
If IsMissing(MyVar) Then
  MsgBox "it is missing"
Else
  MsgBox "it is there"
End If
End Sub

Private Function GetMissing(Optional NotSent As Variant) As Variant
GetMissing = NotSent
End Function



Sun, 23 Nov 2003 22:02:23 GMT  
 How to force an optional parameter to be missing (IsMissing returning True)?
Would using named parameters help?  For instance:

Public Sub Bob(Optional ByVal Param1 As Variant, Optional ByVal Param2 as
Variant)

could be called like:

Bob Param1:=12

or:

Bob Param2:="bob"

or:

Bob 12, "bob"

I agree with Bob (Butler that is) about typed parameters.  Variants have
their
uses, but sorting out a bunch of variants can make the code hard to read,
and
prone to error.


How do I force an optional parameter to be missing without having to
explicitly
miss it out from the call? (There are too many permutation in a 15 optional
parameter function to explicitly performs all possible call...)



Mon, 24 Nov 2003 09:32:46 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Detecting missing objects that are optional parameters

2. optional arguments and Ismissing

3. Using Parameter Queries with Optional Parameters

4. passing optional parameters to the parameters collection

5. Function Parameters - IsMissing

6. IsMissing typed parameter

7. True DBGrid 6.0 - Forcing update of last edit before user leaves grid

8. I am a true programmer!

9. True DBGrid Pro 6.0 + Checkbox (Bin am verzweifeln!)

10. Writing A Function with optional parameters

11. how to declare a function with optional parameters

12. > passing vb6 optional byref parameter into c#

 

 
Powered by phpBB® Forum Software