VARTYPE

VARTYPE(varname)

Returns the number indicating the data type of a variable (Integer).


varnameThe data type name, expression or variable (Object).

REMARKS
* This function never returns the value for vbArray by itself. It is always added to some other value to indicate an array of a particular type.
* The constant vbVariant is only returned in conjunction with vbArray to indicate that the argument to this function is an array of type Variant.
* For example, the value returned for an array of integers is calculated as vbInteger + vbArray, or 8194.
* If an object has a default property, VarType (object) returns the type of the object's default property.
* The values returned by this function are represented by the VBA.vbVarType Enumeration.
* You can use the NOW function to return the current system date and time.
* You can use the TYPENAME function to return the data type of the variable as a string.
* You can use the WEEKDAY function to return the number representing the day of the week for a given date.
* The equivalent .NET function is [[Microsoft.VisualBasic.Information.VarType]]
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print VarType(Empty)                 '= 0 (VBA.vbVarType.vbEmpty)  
Debug.Print VarType( ) '= 1 (VBA.vbVarType.vbNull)
Debug.Print VarType(459) '= 2 (VBA.vbVarType.vbInteger)
Debug.Print VarType(VBA.Weekday(7, vbDayOfWeek.vbMonday)) '= 2 (VBA.vbVarType.vbInteger)
Debug.Print VarType( ) '= 3 (VBA.vbVarType.vbLong)
Debug.Print VarType( ) '= 4 (VBA.vbVarType.vbSingle)
Debug.Print VarType(10.5) '= 5 (VBA.vbVarType.vbDouble)
Debug.Print VarType( ) '= 6 (VBA.vbVarType.vbCurrency)
Debug.Print VarType(VBA.Now()) '= 7 (VBA.vbVarType.vbDate)
Debug.Print VarType("02/12/2021") '= 8 (VBA.vbVarType.vbString)
Debug.Print VarType( ) '= 9 (VBA.vbVarType.vbObject)
Debug.Print VarType( ) '= 10 (VBA.vbVarType.vbError)
Debug.Print VarType(False) '= 11 (VBA.vbVarType.vbBoolean)
Debug.Print VarType( ) '= 12 (VBA.vbVarType.vbVariant)
Debug.Print VarType( ) '= 13 (VBA.vbVarType.vbDataObject)
Debug.Print VarType( ) '= 14 (VBA.vbVarType.vbDecimal)
Debug.Print VarType( ) '= 17 (VBA.vbVarType.vbByte)
Debug.Print VarType( ) '= 36 = VBA.vbVarType.vbUserDefinedType)
Debug.Print VarType( ) '= 8192 (VBA.vbVarType.vbArray)

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top