
Originally Posted by
dw85745
I recognize IsMissing tests only variants. This is the issue I've always had with "Optional" (may be my confusion) in that - if other - than a variant type parameter is passed as "Optional", how you go about testing for whether it exists (the parameter was passed) or not. If I read Si correctly, he indicated to just pass a default value -- which is a solution -- but my understanding regarding the purpose of "Optional" is to reduce the parameter list being passed.
You do reduce the parameter list, if you pick apt defaults then most things won't need to be passed.
With default values, you can (if needed) check against the default value in each case... but in many cases you don't need to bother.
With my previous example, you would normally call it like this:
Code:
Call Example("Command1_Click")
..and if you want a specific description, like this:
Code:
Call Example("Command1_Click", , "oops!")
The code inside the 'Example' routine checks/uses the parameters as apt - in the case of p_strErrorDescription, the code I showed will use the value only if specified (otherwise it will use Err.Description).
For the p_Type parameter, you don't need to do any more checking than your original version.
To replicate your Type, you could change DoError so that the parameters (and checking for defaults) are like this:
Code:
Sub DoError(p_Source as String, _
Optional p_Action as yourActionENum = MsgAndLog, _
Optional p_Type as yourTypeEnum = ERR_CRITICAL, _
Optional p_Data as String = "")
Dim strData as String
If p_Data ="" Then
strData = "ErrNo: " & str$(Err.Number) & "-" & Err.Description
Else
strData = p_Data
End If
(to make the usage more obvious, you could change both instances of "" to something like "<err num and description>")
For the error handler you had earlier, the code could now be reduced to this:
Code:
Error_GetYFromYValue:
Select Case Err.Number
Case 6, 11 'Overflow 'Division by zero
Call DoError(mstrModule & "GetYFromYValue", LogOnly)
Case Else
Call DoError(mstrModule & "GetYFromYValue")
End Select