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

See also  Digital Signage Solutions for Agile Software Development Teams
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist