UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> IsBoolean    

Variants can be useful, even necessary under certain circumstances. However, a procedure that is receiving a variant argument may need to assure that the data actually passed is of a particular. Access VBA does not have a built-in function to determine if a value is actually boolean. This function meets the need.

This function could be used, for example, in a routine which has several optional variant arguments. Variants are required because the IsMissing() function requires a variant argument. In that situation, IsBoolean() can be used to ensure that an optional argument that has been passed is, in fact, a boolean.

Note: VBA does include a function VarType() which can be used to determine the data type of values assigned to Variants. So the test has been revised to

If VarType(rvarValue) = vbBoolean then....


Private Function IsBoolean(rvarValue As Variant) As Boolean
' Procedure: IsBoolean
' Description: test a variant to determine if it is boolean or not
   Const cstrProcedure = "IsBoolean"
   'Dim blnResult As Boolean
   On Error GoTo HandleError
   'blnResult = False
   'this code yields false positives
   '    blnResult = False
   '    If IsNumeric(rvarValue) Then
   '        If rvarValue = CLng(True) Or rvarValue = CLng(False) Then
   '            blnResult = True
   '        End If
   '    Else
   '        blnResult = False
   '    End If

   If VarType(rvarValue) = vbBoolean Then
       IsBoolean = True
       IsBoolean = False

   End If
   Exit Function

   'Insert error handling code here
   Resume HandleExit
End Function

Creative Commons License
IsBoolean by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search

Thank you for your support!
This page has been accessed 11,645 times.  This page was last modified 14:27, 30 June 2011 by Glenn Lloyd.   Disclaimers