Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Harbour Version 0.37 (c) reference Guid - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

TYPE()

Retrieves the type of an expression
---------------------------------------------------------------------------------

 Syntax

        TYPE( <cExp> ) --> <cRetType>  

 Arguments

        <cExp>   must be a character expression.    

 Returns

        <cRetType>   a string indicating the type of the passed 
                  expression.

+------------------------------------------------------------------------+
| <cRetType> | Meaning                                                   |
|------------+-----------------------------------------------------------|
| "A"        | array                                                     |
| "B"        | block                                                     |
| "C"        | string                                                    |
| "D"        | date                                                      |
| "L"        | logical                                                   |
| "M"        | memo                                                      |
| "N"        | numeric                                                   |
| "O"        | object                                                    |
| "U"        | NIL, local, or static variable, or not linked-in function |
| "UE"       | syntax error in the expression or invalid arguments       |
| "UI"       | function with non-reserved name was requested             |
+------------------------------------------------------------------------+

 Description

      This function returns a string which represents the data type  of the
      argument. The argument can be any valid Harbour expression.  If
      there is a syntax error in passed expression then "UE" is returned.
      If there is a call for any non-reserved Harbour function then "UI"
      is returned (in other words there is no call for passed UDF function
      during a data type determination - this is Clipper compatible
      behavior). Additionally if requested user defined function is not
      linked into executable then "U" is returned.

      The data type of expression is checked by invoking a macro compiler
      and by evaluation of generated code (if there is no syntax errors).
      This causes that TYPE() cannot determine a type of local or static
      variables - only symbols visible at runtime can be checked.

      Notice the subtle difference between TYPE and VALTYPE functions.
      VALTYPE() function doesn't call a macro compiler - it simply checks
      the type of passed argument of any type. TYPE() requires a string
      argument with a valid Harbour expression - the data type of this
      expression is returned.

 Examples

       ? TYPE( "{ 1, 2 }" )                            //prints "A"
       ? TYPE( "IIF(.T., SUBSTR('TYPE',2,1), .F.)" )   //prints "C"
       ? TYPE( "AT( 'OK', MyUDF())>0" )                //prints "UI"
       ? TYPE( "{ 1, 2 }[ 5 ]" )                       //prints "UE"

       //--------------------------------------------------------

       LOCAL c
       PRIVATE a:="A", b:="B"
       ? TYPE( "a + b + c" )     //prints: "U" ('C' variable is a local one)

       //--------------------------------------------------------

       LOCAL cFilter := SPACE( 60 )
       ACCEPT "Enter filter expression:" TO cFilter
       IF( TYPE( cFilter ) $ "CDLMN" ) )
          // this is a valid expression
          SET FILTER TO &cFilter
       ENDIF

  

Status

      Ready

 Compliance


      - Incompatibility with Clipper:  In the following code:

      PRIVATE lCond := 0  ? TYPE( "IIF( lCond, 'true', MyUDF() )" )

      Clipper will print "UE" - in Harbour the output will be "UI"

      - if "UI" is returned then the syntax of the expression is  correct.
      However invalid arguments can be passed to  function/procedure that
      will cause runtime errors during  evaluation of expression.

 Files

      Library is rtl



See Also: VALTYPE()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson