Eval

See Also: Miscellaneous Functions, String Functions, Get_StrictEval

Purpose

Eval returns the value of a string, evaluated as an expression at runtime.

Return Type

String

Syntax

(Eval( {string-expression} ))

What It Does

The eval function provides evaluation at runtime of expressions stored as strings.

Procedure Test

    String sExpression sOperator

    Integer iOperand1 iOperand2 iResult

 

    Move 10  to iOperand1

    Move 8   to iOperand2

    Move "+" to sOperator

    Move (String (iOperand1) + sOperator + String(iOperand2)) to sExpression

    Move (Eval(sExpression)) to iResult

End_Procedure

In this example, string that is stored in sExpression is parsed and evaluated, the answer (18) is stored in the integer variable iResult.

Procedure Test

    String sExpression sOperator sOperand1 sOperand2

    Number nResult

 

    Find Gt Invt.Recnum

    Move "Invt.Unit_Price" to sOperand1

    Move "Invt.On_Hand" to sOperand2

    Move "*" to sOperator

    Move (sOperand1 + sOperator + sOperand2)  to sExpression

    Move (Eval(sExpression)) to nResult

 

    Send Info_Box ("The result of\n\n" + sExpression + "\n\nis" * String (nResult)) "Result"

End_Procedure

The result of the record value invt.unit_price multiplied by the value of invt.on_hand will be shown in the message box. For this sample, the file invt needs to be opened before and the Windows.pkg needs to be USEd.

Notes