Click or drag to resize

Type Function (String, Long)

X#
Determine the data type of an expression represented as a string.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.21
Syntax
[NeedsAccessToLocalsAttribute(FALSE)]
 FUNCTION Type(
	cString AS STRING,
	nArray AS LONG
) AS STRING
Request Example View Source

Parameters

cString
Type: String
A string that contains an expression whose type is to be determined.
It cannot contain undeclared variables or functions that are not intended for used with macros
If cString does not exist, "U" is returned.
nArray
Type: Long

Return Value

Type: String
One of the following characters: Returns Meaning A Array B Block C String D Date L Logical M Memo N Numeric O Object U NIL, local, or static UE Error syntactical UI Error indeterminate
Remarks
Type() uses the macro operator (&) to determine the argument's data type; therefore, you cannot use it to determine the data type of undeclared variables or functions that are not intended for used with macros.
Use UsualType() for these expressions.
Tip Tip
Array references: References to private and public arrays return "A." References to array elements return the type of the element. If():
To return the appropriate data type for an If() expression, Type() evaluates the condition then returns the type of the evaluated path.
If either the If() condition or the evaluated path are invalid, Type() returns "UE." Testing parameters: Type() can only test the validity of parameters received using the PARAMETERS statement. Testing a parameter declared as part of a FUNCTION or PROCEDURE declaration always returns "U." because local parameters do not have a symbol in the symbol table.
To determine whether an argument was skipped or left off the end of the argument list, compare it to NIL or use IsNil().
Examples
These examples demonstrate various results from invocations of Type():
X#
 1? Type('Substr("Hi There", 4, 5)')        // C
 2? Type("UdF()")                    // UI
 3? Type('If(TRUE, "true", 12)')            // C
 4PROCEDURE NilParameters()
 5    PARAMETERS cParam1, nParam2, uParam3
 6    IF cParam1 = NIL
 7        ? "First parameter was not passed"
 8        cParam1 := "Default value"
 9    ENDIF
10    IF Type("nParam2") = "U"
11        ? "Second parameter was not passed"
12    ENDIF
13    IF IsNil(uParam3)
14        ? "Third parameter was not passed"
15    ENDIF
16.
17. <paramref name="Statements" />
18.
This example shows the difference between Type(), ValType(), UsualType(), and UsualVal(). Note that Type() macro-expands the contents of the string before evaluating it, whereas UsualType() does not:
X#
1num := 10                    // Undeclared variable
2? Type("num + num")            // N
3? ValType(num + num)        // N
4? UsualType("num + num")        // 7 (stands for STRING)
5? UsualVal(num + num)        // 20
See Also