devxlogo

IsMissing returns False with non-Variant arguments

IsMissing returns False with non-Variant arguments

Every now and then I forget that the IsMissing function always returns False when the argument is not a Variant value. This happens because IsMissing does nothing more than converting its argument to Variant and testing for a special VarType value. For this reason, the following code is a symptom of a probable bug:

Sub DoSomething(Optional value As Long)  If IsMissing(value) Then    ' this code will be NEVER executed !!!  End If  '...End Sub

Another little known quirk of the IsMissing function is that it always return False once the parameter has been set to an explicit value from within the procedure, as in:

Sub DoSomething(value1 As String, Optional value2 As Variant)  If IsMissing(value2) Then    value2 = value1  End If  '...  If IsMissing(value2) Then    ' this code will be NEVER executed !!!  End If  '...End Sub

devx-admin

Share the Post: