How I can check validity of a macro ?

PROC MAIN()

    nResult   := NIL
    nDivident := 1
    nDivisor  := 0
    cMacro    := " nResult := nDivident / nDivisor "  
    QOutResult( nDivident, nDivisor, cMacro ) // 1  0  UE macro is inValid

    nDivisor  := 2
    QOutResult( nDivident, nDivisor, cMacro ) // 1  2  N  Result is :  0.50

    cMacro    := "AT( 'OK', MyUDF() ) > 0"              
    QOutResult( 'AT( OK', 'MyUDF()', cMacro ) // AT( OK ... U macro is inValid

    cMacro    :=  "{ 1, 2 }[ 2 ]"                       
    QOutResult( '{ 1, 2 }', '[2]', cMacro ) // { 1, 2 } [2]   N Result is : 2

    cMacro    :=  "{ 1, 2 }[ 5 ]"  
    QOutResult( '{ 1, 2 }', '[5]', cMacro ) // { 1, 2 } [5] UE macro is inValid

    lCond := 0
    cMacro    :=  "if( lCond, 'true', MyUDF() )"
    QOutResult( lCond, '', cMacro )           // 0        U macro is inValid   
    ?
    WAIT

RETU // Main()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROC QOutResult( xVal1, xVal2, cMacro )

	LOCAL cType := TYPE( cMacro )

	? PAD( xVal1, 10 ), PAD( xVal2, 10 ),  PAD( cType, 3 )

    IF ( cType # "U") 
       ?? "Result is :", &cMacro
    ELSE
       ?? "macro is inValid"
    ENDIF

RETU // QOutResult()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._

See Also:

& (macro evaluation unary) Operator 

Macro Compiler

HB_SetMacro()

ValType()

TYPE()

C5_TYPE()

Advertisements

HB_IsBlock

HB_IsBlock()

Tests if the value returned by an expression is a Code block.

Syntax

      HB_IsBlock( <expression> ) --> lIsCodeblock

Arguments

<expression> an expression of any data type

Return

.T. (true) if the value returned by <expression> is a code block, otherwise .F. (false) is returned.

Description

HB_IsBlock() is used to test if a variable contains a code block or if the result of an expression is of data type Code block. The function can be used as a replacement for the expression: Valtype(<expression>)==”B”.

Seealso

HB_IsArray(), HB_IsByRef(), HB_IsDate(), HB_IsHash(), HB_IsLogical(), HB_IsMemo(), HB_IsNIL(), HB_IsNull(), HB_IsNumeric(), HB_IsObject(), HB_IsPointer(), HB_IsString(), Type(), Valtype()

HB_IsString

HB_IsString()

Tests if the value returned by an expression is a character string.

Syntax

      HB_IsString( <expression> ) --> lIsString

Arguments

<expression> an expression of any data type

Return

.T. (true) if the value returned by <expression> is a character string, otherwise .F. (false) is returned.

Description

HB_IsString() is used to test if a variable contains a character string or if the result of an expression is of data type Character. The function can be used as a replacement for the expression: Valtype(<expression>)==”C”.

Seealso

HB_IsArray(), HB_IsBlock(), HB_IsByRef(), HB_IsDate(), HB_IsLogical(), HB_IsHash(), HB_IsMemo(), HB_IsNIL(), HB_IsNull(), HB_IsNumeric(), HB_IsObject(), HB_IsString(), Type(), Valtype()

HB_IsPointer

HB_IsPointer()

Tests if the value returned by an expression is a pointer.

Syntax

      HB_IsPointer( <expression> ) --> lIsPointer

Arguments

<expression> an expression of any data type

Return

.T. (true) if the value returned by <expression> is a pointer, otherwise .F. (false) is returned

Description

HB_IsPointer() is used to test if a variable contains a pointer or if the result of an expression is of data type Pointer. The function can be used as a replacement for the expression: Valtype(<expression>)==”P”.

Seealso

HB_IsArray(), HB_IsBlock(), HB_IsByRef(), HB_IsDate(), HB_IsLogical(), HB_IsHash(), HB_IsMemo(), HB_IsNIL(), HB_IsNull(), HB_IsNumeric(), HB_IsObject(), HB_IsString(), Type(), Valtype()

HB_IsObject

HB_IsObject()

Tests if the value returned by an expression is an object.

Syntax

      HB_IsObject( <expression> ) --> lIsObject

Arguments

<expression> an expression of any data type

Return

.T. (true) if the value returned by <expression> is an object, otherwise .F. (false) is returned.

Description

Function HB_IsObject() is used to test if a variable contains an object or if the result of an expression is of data type Object. The function can be used as a replacement for the expression: Valtype(<expression>)==”O”.

Seealso

HB_IsArray(), HB_IsBlock(), HB_IsByRef(), HB_IsDate(), HB_IsLogical(), HB_IsHash(), HB_IsMemo(), HB_IsNIL(), HB_IsNull(), HB_IsNumeric(), HB_IsPointer(), HB_IsString(), Type(), Valtype()

HB_IsNumeric

HB_IsNumeric()

Tests if the value returned by an expression is a numeric value.

Syntax

      HB_IsNumeric( <expression> ) --> lIsNumeric

Arguments

<expression> an expression of any data type

Return

.T. (true) if the value returned by <expression> is of data type Numeric, otherwise .F. (false) is returned.

Description

Function HB_IsNumeric() is used to test if a variable contains a numeric value or if the result of an expression is of data type Numeric. The function can be used as a replacement for the expression: Valtype(<expression>)==”N”.

Seealso

HB_IsArray(), HB_IsBlock(), HB_IsByRef(), HB_IsDate(), HB_IsLogical(), HB_IsHash(), HB_IsMemo(), HB_IsNIL(), HB_IsNull(), HB_IsObject(), HB_IsPointer(), HB_IsString(), Type(), Valtype()

HB_IsNull

HB_IsNull()

Tests if the value returned by an expression is empty.

Syntax

      HB_IsNull( <expression> ) --> lIsNull

Arguments

<expression> an expression of data type Array, Character or Hash. If a value of a different data type is passed, a runtime error is raised.

Return

.T. (true) if the value returned by <expression> is an empty array, character string or hash, otherwise .F. (false) is returned.

Description

Function HB_IsNull() is used to test if a variable contains an empty value of data type Array, Character or Hash. The function can be used as a replacement for the expression: Len(<expression>)==0.

Seealso

HB_IsArray(), HB_IsBlock(), HB_IsByRef(), HB_IsDate(), HB_IsHash(), HB_IsLogical(), HB_IsMemo(), HB_IsNIL(), HB_IsNumeric(), HB_IsObject(), HB_IsPointer(), HB_IsString(), Type(), Valtype()