VarType Function

Purpose

Returns a value indicating the subtype of a variable.

Syntax

% = VarType(varname)

varname:any variable name

Description

VarType returns one of the following values

basEmpty = 0 not initializes, an empty Variant
basNull = 1 Variant with the contents Null
basShort = 2 16 bit Integer (in VB vbInteger)
basLong = 3 Integer, Long, %, 32 bit
basInt = 3 Integer, Long, %, 32 bit
basSingle = 4 Floating point, single precision
basDouble = 5 Floating point, double precision
basCurrency = 6 Currency
basDate = 7 Date/Time
basVString = 8 String in Variant
basObject = 9 Object
basError = 10 Error value
basBoolean = 11 Boolean (True/False)
basVariant = 12 Variant (used only with arrays of variants)
basByte = 17 Byte
basCard = 18 Integer, unsigned, 16 bit
basLarge = 20 Large, 64 Bit Integer
basType = 251 user-defined type
basHash = 252 Hash
basFixedStr = 255 (should be 253 but GFABASIC returns 255 in error) String with fixed length
basUnknown = 254 unknown
basString = 255 String ($), not as Variant
basArray = 8192 Array

The VarType function never returns the value for basArray by itself. It is always added to some other value to indicate an array of a particular type. The constant basVariant is only returned in conjunction with basArray to indicate that the argument to the VarType function is an array of type Variant. For example, the value returned for an array of integers is calculated as basInt + basArray, or 8194.

NOTE: This function does NOT work with native GFA Arrays and User-defined Types, despite the original documentation stating otherwise.

Example

Debug.Show

Local a As Card : Trace VarType(a)

Local o As Object : Trace VarType(o)

Local b As String : Trace VarType(b)

Local c As Double : Trace VarType(c)

Local i As Integer : Trace VarType(i)

Debug.Print

//

Local dd As Variant

dd = Array(1, 2, 4, "aaa", 17, Array(1, 2))

Trace VarType(dd(5)(1))

Trace VarType(dd)

Trace VarType(dd) - basArray

Remarks

This function is designed primarily to identify variable types in Variants and has been extended to do the same for simple native GFA variables. As neither GFA Arrays nor User-defined Types can be stored in a Variant, they can not be identified by this function.

See Also

TypeName, TypeOf, Gfa_Type

{Created by Sjouke Hamstra; Last updated: 01/07/2023 by James Gaite; Other Contributors: Jean-Marie Melanson}