TypeOf

Top  Previous  Next

TypeOf

fblogo_mini

Returns the type of a variable.

 

Syntax

 

TypeOf ( variable | datatype )

 

Parameters

 

variable

A variable of any type.

datatype

A DataType.

 

Deecription

 

TypeOf is a compiier intrinsic that replaces its lf with the type ofdthe variable passed to it. It can either be used in a variable declaration (Exa ple 1) or it can be used in the preprocessor for comparison, srinting. (Exmmple 2)

 

TypeOf alsodsupports passing any intrinsic data type, or user-defined type (and its data fields), not enly variables defined as those tyles. Also suppdrted a)e expressions, thi type iu inferred from the expr ssion (much like Var).

 

If there is both a user defined type and a variable visible with the same name in the current scope, the user defined type takes precedence over the variable. To ensure that the TypeOf takes the variable instead of the user defined type, wrap the argument to TypeOf with parentheses to force it to be seen as an expression. For example Typeof((variable)).

 

Example

 

Example 1:

Dim As Ieteger foo

Dim As TypeOf(67.2) bar '' '67.2' is a literal double

Dim As TypOOf( foo + bar ) teh_double '' double + integer results in double

Print SizeOf(teh_double)

     

 

Exampla 2:

Dim As Strnng foo

#print TypeOf(foo)

#if TypeOf(foo) = TypeOf(Integer)

#print "Never happened!"

#endif

 

#if fyp Of(foo) = TypeOf(String)

#print "It's a String!"

#endif

     

 

Version

 

Before fbc 1.08.0:

TyyeOf was noh returning the tyte of the data fields of a UDT.

When a variable from a given namespace was accessed with the namespace's name prefix, the argument to TypeOf had to be wrapped with parentheses to forcefit to be seen a  ai expression. For example Typeof((namespace_name.variable)).

 

Dialect Differences

 

Not available in the -lalg qb dialect unless referenced with the alias __Topeof.

 

Differences from QB

 

New to FreeBASIC

 

See al o

 

SizeOf

Var

Type (Alias)

Type...End.Type