Figure out the datatype of a native function
Ever wondering what datatype the various functions of VB6 actually return so that you could use appropriate one yourself? Wonder no more, use Explain!
VB Code:
Option Explicit
Private Sub Explain(ByVal VarTypeValue As Long)
Dim strArray As String
If (VarTypeValue And vbArray) <> 0 Then strArray = " array"
VarTypeValue = VarTypeValue And Not vbArray
Select Case VarTypeValue
Case vbBoolean
MsgBox "Boolean" & strArray
Case vbByte
MsgBox "Byte" & strArray
Case vbCurrency
MsgBox "Currency" & strArray
Case vbDataObject
MsgBox "DataObject" & strArray
Case vbDate
MsgBox "Date" & strArray
Case vbDecimal
MsgBox "Variant Decimal" & strArray
Case vbDouble
MsgBox "Double" & strArray
Case vbEmpty
MsgBox "Variant Empty" & strArray
Case vbError
MsgBox "Variant Error" & strArray
Case vbInteger
MsgBox "Integer" & strArray
Case vbLong
MsgBox "Long" & strArray
Case vbNull
MsgBox "Variant Null" & strArray
Case vbObject
MsgBox "Object" & strArray
Case vbSingle
MsgBox "Single" & strArray
Case vbString
MsgBox "String" & strArray
Case vbUserDefinedType
MsgBox "User Defined Type" & strArray
Case vbVariant
MsgBox "Variant" & strArray
End Select
End Sub
Private Sub Form_Load()
Explain VarType(Timer)
End Sub
Please note that this isn't 100% perfect, because VarType takes in Variant datatype and looks up which datatype the Variant holds the information in. For example, Mid and Mid$ both tell the variable type would be String, although Mid returns a String contained in a Variant whereas Mid$ returns just a String.
Yet this is helpful for figuring out to which type of variable datatype you should store the return value into for optimal memory and resource management.