Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB5,VB6
Expertise: beginner
Apr 20, 1999

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
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date