Function Type() Foundation
Determines the data type of an expression.
Type( <cExpression> ) --> cType
The return value of Type() is one or two characters which specify the data type of the value of <cExpression>. The following table lists the possible data types and return values of Type():
Return value | Data type |
---|---|
A | array |
B | code block |
C | character string |
D | date value |
L | logical value |
M | memo field |
N | numeric value |
O | object |
U | NIL or unknown |
UE | Syntactically faulty expression |
Type() is a debugging function which determines the data type of an expression passed in the form of a character string. Type() returns a character string identifying the data type. The function determines the data type using the macro operator (&), which means the character expression is executed and the data type of the result determined. Type() differs from the function Valtype(). Valtype() determines the data type directly so can also determine the data type of variables declared as LOCAL or STATIC.
// The example shows possible return values of Type()
PROCEDURE Main
MEMVAR oGet
PRIVATE oGet := GetNew()
? Type( "{1,2,3}" ) // result: A
? Type( "{|| 1 }" ) // result: B
? Type( "'Xbase++'" ) // result: C
? Type( "Date()" ) // result: D
? Type( ".T." ) // result: L
? Type( "1" ) // result: N
? Type( "Customer->notice" ) // result: M
? Type( "oGet" ) // result: O
? Type( "Val(" ) // result: UE
? Type( "NIL" ) // result: U
RETURN
// The example demonstrates the difference between Type() and
// Valtype() with variables and functions of different
// visibility or storage class. Type() uses the macro
// operator to determine the data type of an expression
// in form of a character string. Valtype() determines the
// data type of the expression directly.
PROCEDURE Main
LOCAL cArray := "{1,2,3}"
MEMVAR pnNumeric
PRIVATE pnNumeric := 10
? Valtype( cArray ) // result: C
? Type( cArray ) // result: A (contents of LOCAL)
? Valtype( "cArray" ) // result: C
? Type( "cArray" ) // result: U (LOCAL variable)
? Valtype( "pnNumeric" ) // result: C
? Type( "pnNumeric" ) // result: N (contents of PRIVATE)
? Valtype( GlobalFunc() ) // result: L (function value)
? Type("GlobalFunc()") // result: L (function value)
? Valtype( StaticFunc() ) // result: N (function value)
? Type("StaticFunc()") // result: U (STATIC FUNCTION)
RETURN
FUNCTION GlobalFunc()
RETURN .T.
STATIC FUNCTION StaticFunc()
RETURN 100
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.