Function Comparisons Class

VarTypeFromString

"Variable Type From String" or "String To Variable Type" Converts the name of a data type into the VarType value representing that data type.

Signature (Visual Basic / VBA)

Public Function VarTypeFromString( _
    ByVal vVarType As Variant _
    ) As Variant

Code Example

    VarTypeFromString("String") = vbString
    VarTypeFromString("STRING") = vbString
    VarTypeFromString("LONG") = vbLong
    VarTypeFromString("variant ARRAY") = vbVariant + vbArray
    IsNull(VarTypeFromString("Unknown")) = True

Parameters

Parameter Description
vVarType The name of a Visual Basic data type whose VarType value is to be returned. Function returns Null if vVarType is Null or cannot be fixed up to a String. Function returns Null if vVarType is not the name of a Visual Basic data type.

Notes & Version History

Note The match is case-insensitive, so it does not matter if the data type name is in upper- or lower-case.
v1.2 BugFix Changed function to correctly recognize arrays of types other than Variant. Arrays are now identified by names like "Currency Array" or "Variant Array".
v1.5 Change This function has been extended to support the new Decimal data type in VB 6.0.