TypeName Function

Purpose

Returns a String that provides information about a variable.

Syntax

$ = TypeName[$](varname)

varname:variable

Description

TypeName returns a String naming the type of the variable, in contrast with VarType which only returns a constant representing the type.

Boolean Boolean (True/False)
Byte Byte
Card Integer, unsigned, 16 bit
Currency Currency
Date Date/Time
Double Floating point, double precision
Emptynot initialized, an empty Variant
Hash[] Hash
Large Large, 64 Bit Integer
Long Integer, Long, %, 32 bit
Null Variant or Handle with the contents Null
Single Floating point, single precision
Short 16 bit Integer
String (Fixed) String ($) including String in Variant
Variant Variant (used only with arrays of variants)

Objects, Arrays and User-defined Types

When varname is an Object, the return value is the object type or, if no object has been assigned, then Nothing. Objects stored using OCX variables, Variants, the Picture and the Object variable types can be queried using this function.

With arrays, the function only works with Arrays in Variants and returns type() where type is the variable type of the array, e.g. a Double array would return "Double()".

This function does not work with User-defined Types nor elements of UDTs, despite advice otherwise in the original documentation.

Example

OpenW Hidden 1

Debug "General Variables"

Local ca As Card : Trace TypeName(ca)

Local i% : Trace TypeName(i%)

Local st$ : Trace TypeName(st$)

Local sh& : Trace TypeName(sh&)

Local e As Date : Trace TypeName(e)

//

Debug : Debug "Variants"

Local va As Variant : Trace TypeName(va)

va = 11122455.2255 : Trace TypeName(va)

va = "A string" : Trace TypeName(va)

va = Null : Trace TypeName(va)

//

Debug : Debug "Handles"

Local g As Handle : g = V:i% : Trace TypeName(g)

//

Debug : Debug "Objects"

Local f As Picture : Trace TypeName(f)

Set f = Win_1.PrintPicture : Trace TypeName(f) : Set f = Nothing

Local lbl As Label : Trace TypeName(lbl)

Ocx Label lbl1 : Set lbl = lbl1 : Trace TypeName(lbl)

Local obj As Object : Trace TypeName(obj)

Set obj = CreateObject("InternetExplorer.Application") : Trace TypeName(obj) : Set obj = Nothing

Local ova As Object : Trace TypeName(ova)

Ocx TextBox txt : Set ova = txt : Trace TypeName(ova)

//

Debug : Debug "Arrays in Variants"

Local aiv As Variant : aiv = Array(1, 2, 3) As Byte

Trace TypeName(aiv)

//

CloseW 1

Debug.Show

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

TypeOf, VarType

{Created by Sjouke Hamstra; Last updated: 07/07/2019 by James Gaite}