Is VarType/TypeName replacement functions

So we have the VarType and TypeName functions already implemented in VBA, but, they require variables as the feeder, no considering expressions.

How can we determine if a value is an Integer a Byte or a Long?, a Single or a Double?

Here are some functions that can help to filter the type of variables by their values:

Public Function IsDouble(ByVal value As Variant) As Boolean
If IsNumeric(value) Then IsDouble = Not IsLong(value)
End Function

Public Function IsSingle(ByVal value As Variant) As Boolean
IsSingle = IsDouble(value) And (1.401298E-45 <= VBA.Abs(value) Or VBA.Abs(value) <= 3.402823E+38)
End Function

Public Function IsLong(ByVal value As Variant) As Boolean
If IsNumeric(value) Then IsLong = (VBA.CLng(value) = VBA.Val(value))
End Function

Public Function IsInteger(ByVal value As Variant) As Boolean
IsInteger = (IsLong(value) And VBA.Abs(value) <= 32768)
End Function

Public Function IsByte(ByVal value As Variant) As Boolean
IsByte = (IsLong(value) And VBA.Abs(value) <= 255)
End Function

Public Function IsString(ByVal value As Variant) As Boolean
IsString = (VarType(value) = vbString)
End Function

Public Function IsBoolean(ByVal value As Variant) As Boolean
Dim strTrueLocal As String: strTrueLocal = VBA.CStr(True)
Dim strFalseLocal As String: strFalseLocal = VBA.CStr(False)
IsBoolean = IsString(value) And (VBA.UCase$(value) = "TRUE" _
Or VBA.UCase$(value) = strTrueLocal _
Or VBA.UCase$(value) = "FALSE" _
Or VBA.UCase$(value) = strFalseLocal)
End Function
[/sourcecode]

One thought on “Is VarType/TypeName replacement functions”

  1. Pingback: Database maker

Leave a Reply

Your email address will not be published. Required fields are marked *