xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

Valtype()

Determines the data type of the value returned by an expression.

Syntax

Valtype( <expression >) --> cDataType

Arguments

<expression>
This is an expression of any data type.

Return

The function returns a character string identifying the data type of <expression> (see description).

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 valueData type
AArray
BCode block
CCharacter string
DDate value, DateTime value
HHash
LLogical value
MMemo field
NNumeric value
OObject
PPointer to function, procedure or method
UUndefined 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.

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe