[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
TYPE()
Determine the type of an expression
------------------------------------------------------------------------------
Syntax
TYPE(<cExp>) --> cType
Arguments
<cExp> is a character expression whose type is to be determined.
<cExp> can be a field, with or without the alias, a private or public
variable, or an expression of any type.
Returns
TYPE() returns one of the following characters:
TYPE() Return Values
------------------------------------------------------------------------
Returns Meaning
------------------------------------------------------------------------
A Array
B Block
C Character
D Date
L Logical
M Memo
N Numeric
O Object
U NIL, local, or static
UE Error syntactical
UI Error indeterminate
------------------------------------------------------------------------
Description
TYPE() is a system function that returns the type of the specified
expression. It can test expression validity as long as the expression
uses CLIPPER.LIB functions and does not reference local or static
variables, user-defined functions, or built-in functions supplied in
EXTEND.LIB.
TYPE() is like VALTYPE() but uses the macro operator (&) to determine
the type of the argument. This precludes the use of TYPE() to determine
the type of local and static variables. VALTYPE(), by contrast,
evaluates an expression and determines the data type of the return
value. This lets you determine the type of user-defined functions as
well as local and static variables.
Notes
. 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, and 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 the parameter to NIL
or use VALTYPE().
. User-defined and EXTEND.LIB functions: If a reference is made
anywhere in an expression to a function not found in CLIPPER.LIB (a
user-defined or EXTEND.LIB function), TYPE() returns "UI." If the
user-defined function is not linked into the current program, TYPE()
returns "U."
Examples
. These examples demonstrate various results from invocations of
TYPE():
? TYPE('SUBSTR("Hi There", 4, 5)') // Result: C
? TYPE("UDF()") // Result: UI
? TYPE('IF(.T., "true", 12)') // Result: C
. This example shows two methods for testing for the existence
and type of declared parameters:
FUNCTION TestParams
PARAMETERS cParam1, nParam2
IF cParam1 = NIL
? "First parameter was not passed"
cParam1 := "Default value"
ENDIF
IF TYPE('nParam2') == "U"
? "Second parameter was not passed"
ENDIF
.
. <statements>
.
RETURN NIL
Files Library is CLIPPER.LIB.
See Also:
VALTYPE()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson