Atlanta Custom Software Development 

   Search        Code/Page

User Login



Forgot the Password?
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
» Regular Expr Tester
» Free Tools

Manufacture a Missing value

Total Hit ( 3044)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article



Visual Basic doesn't provide you with a means for creating a Missing value, a feature that in some cases would prove useful in order to simplify the syntax of calls to procedures that expects a variable number of arguments. It isn't difficult, however, to create such a value programmatically, as follows:

' never pass an argument to this function

Click here to copy the following block
Function MissingValue(Optional DontPassMe As Variant) As Variant
  ' If an argument is passed, raise the "Invalid Procedure Call" error
  If Not IsMissing(DontPassMe) Then Err.Raise 5   
  MissingValue = DontPassMe
End Function

There is an alternative way, however, that doesn't require that you intentially avoid to pass an Optional argument to a procedure. This latter method actually manufactures the internal representation of a Variant:

Click here to copy the following block
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As _
  Any, source As Any, ByVal bytes As Long)

Function MissingValue() As Variant
  ' A "missing" value is actually an error code equal to hex 80020004
  ' so here we store the integer part of this value
  MissingValue = &H80020004
  ' and then we modify the VarType to vbError (= 10)
  CopyMemory MissingValue, 10, 2
End Function

Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with, SQL Server and other MS technologies. He is, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )

Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.