Condividi tramite


TYPE( ) Function

Evaluates an expression and returns the data type of its contents.

TYPE(cExpression)

Return Values

Character

Parameters

  • cExpression
    Specifies the expression to be evaluated, which can be a variable, field, memo field, or any other expression. The expression must be passed as a character string; place quotation marks around the names of memory variables, fields, and so on. If you do not place quotation marks around the expression, the TYPE( ) function evaluates the contents of the string. If the contents cannot be evaluated as a valid FoxPro expression, TYPE() returns "U" (undefined expression).

Remarks

The following table lists the character values TYPE( ) returns and their corresponding data types:

Data type Character returned
Character C
Numeric (also float, double, and integer) N
Currency Y
Date D
DateTime T
Logical L
Memo M
Object O
General G
Screen (created with SAVE SCREEN) S
Undefined type of expression U

If you pass an array as a parameter to TYPE( ), then the data type returned corresponds to the first element in the array. If you want to check the data type for a specific array element, then you must specify that element in the parameter. For example:

? TYPE("myarray[3]")

You can also use the TYPE( ) function to check if a memory variable is an array. For example:

? TYPE("myarray[1]")#"U"

Example

CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE customer  && Opens Customer table
nTest = 1.01
cTest = "String"

CLEAR
? TYPE('customer.contact')  && Displays C
? TYPE('(12 * 3) + 4')  && Displays N
? TYPE('DATE( )')  && Displays D
? TYPE('.F. OR .T.')  && Displays L
? TYPE('ANSWER=42')  && Displays U
? TYPE('$19.99')  && Displays Y
? TYPE('nTest')  && Displays N
? TYPE('cTest')  && Displays C

See Also

EVALUATE( ) | SAVE SCREEN | VARTYPE( )