Partager via


TYPE( ) Function

Returns the data type of an expression.

Note

VARTYPE( ) is similar to the TYPE( ) function, but VARTYPE( ) is faster and does not require quotation marks ("") to enclose the specified expression.

TYPE(cExpression [, 1])

Parameters

  • cExpression
    Specifies the expression, which can be a variable, array, field, memo field, or other expression, for which the data type is returned.

    Note

    You must pass the expression as a character string by enclosing the expression with quotation marks (""). If you do not enclose the expression with quotation marks, TYPE( ) evaluates the contents of the expression.

  • 1
    Include the optional parameter 1 to determine if cExpression is an array or a Collection Class. COM objects are not supported with the 1 parameter.

Return Value

Character. TYPE( ) returns a character representing the data type of the specified expression.

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

Return value

Data type

A

Array (only returned when the optional 1 parameter is included)

C

Character, Varchar, Varchar (Binary)

If the optional 1 parameter is included, a return value of C indicates that the data type is a collection.

D

Date

G

General

L

Logical

M

Memo

N

Numeric, Float, Double, or Integer

O

Object

Q

Varbinary

S

Screen

Note

The Screen type is created when using the SAVE SCREEN command. For more information, see SAVE SCREEN Command.

T

DateTime

U

Undefined type of expression or cannot evaluate expression.

If the optional 1 parameter is included, a return value of U indicates that the data type is not an array.

W

Blob

Y

Currency

Remarks

If you pass an array as a parameter to TYPE( ), 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, 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"

Note

TYPE( ) cannot be used to evaluate UDFs (user-defined functions).

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

Reference

EVALUATE( ) Function

VARTYPE( ) Function

Other Resources

Data and Field Types

Functions

Language Reference (Visual FoxPro)