xHarbour Reference Documentation > Function Reference |
Determines the data type of the value returned by an expression.
Valtype( <expression >) --> cDataType
The function returns a character string identifying the data type of <expression> (see description).
Valtype() is used to determine the data type of an arbitrary expression, including lexically scoped variables (GLOBAL, LOCAL, STATIC), and (user-defined) functions and methods. Valtype() is more powerful than Type() which determines the data type of macro expressions only.
The function returns one of the following characters:
Return values of Valtype()
Return value | Data type |
---|---|
A | Array |
B | Code block |
C | Character string |
D | Date value, DateTime value |
H | Hash |
L | Logical value |
M | Memo field |
N | Numeric value |
O | Object |
P | Pointer to function, procedure or method |
U | Undefined symbol or NIL |
Note: if any part of <expression> does not exist, Valtype() generates a runtime error.
Important: both, Date and DateTime values, yield "D" with Valtype(). Use function HB_IsDateTime() to distinguish Date from DateTie values.
See also: | Type(), HB_IsArray(), HB_IsBlock(), HB_IsByRef(), HB_IsDate(), HB_IsDateTime(), HB_IsHash(), HB_IsLogical(), HB_IsMemo(), HB_IsNIL(), HB_IsNull(), HB_IsNumeric(), HB_IsObject(), HB_IsPointer(), HB_IsString() |
Category: | Debug functions , Pointer functions |
Source: | rtl\valtype.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example shows all possible return values of Valtype() PROCEDURE Main LOCAL aArray := { 1, 2, 3 } LOCAL bBlock := {|x| 1+x } LOCAL cChar := "xHarbour" LOCAL dDate := Date() LOCAL hHash := Hash() LOCAL lLogic := .F. LOCAL nNumber := 123.45 LOCAL oObject := GetNew() LOCAL pPtr := ( @Test() ) LOCAL uNIL := NIL USE Customer ALIAS Cust ? Valtype( aArray ) // result: A ? Valtype( bBlock ) // result: B ? Valtype( cChar ) // result: C ? Valtype( dDate ) // result: D ? Valtype( hHash ) // result: H ? Valtype( lLogic ) // result: L ? Valtype( Cust->notes ) // result: M ? Valtype( nNumber ) // result: N ? Valtype( oObject ) // result: O ? Valtype( pPtr ) // result: P ? Valtype( uNIL ) // result: U ? Valtype( Date() ) // result: D ? Valtype( oObject:hasFocus() ) // result: L Test( pPtr, hHash ) // result: P H ? Valtype( IIf( .T., "A", 1 ) ) // result: C ? Valtype( "A" ) // result: C ? Valtype( A ) // result: runtime error RETURN PROCEDURE Test( p1, p2 ) ? Valtype( p1 ), Valtype( p2 ) RETURN
http://www.xHarbour.com