Salesforce

EvalStr (Magic xpa 4.x)

« Go Back

Information

 
Created BySalesforce Service User
Approval Process StatusPublished
Objective
Description

EvalStr (Magic xpa 4.x)

Lets you construct a Magic xpa expression at runtime, then execute it.

This is useful when you want to store “macro” instructions in a DB Table, for instance. The instructions can be created by one program, and executed by another.

This function can execute any other Magic xpa function. In this test case, you can type in any text you like, and Magic xpa will execute it.

Syntax:

EvalStr(string, default value)

Parameters:

string: A string that evaluates to a valid Magic xpa expression. It can be a literal string in single quotation marks, or an Alpha variable. The maximum allowed length of a function's string parameter is 32,768 characters.

default value: The function returns the default value of the first parameter that is found to be an invalid expression. The default value of the function must match the expected attribute of the function according to the context of where the function is placed in the expression.

For example, in the expression 1 + EvalStr(string, default value), the expected attribute of the default function is Numeric.

Returns:

The evaluated value of the expression given by the first parameter. If this expression is invalid, the default value is returned.

Example:

EvalStr(A,0), where A='3 + 2', returns the value of 5.

EvalStr(A,0), where A='3 + ', returns the value of 0.

Note:

If the expression represents a single quote character (for a string or a literal), you should provide two single quotes for each single quote.

For example:

EvalStr('DbDel(''1''DSOURCE,''MYFILE.DAT'')','TRUE'LOG)

or

EvalStr('A' & 'B',' ') = 'AB'

If strings are not surrounded by quotes, they are regarded as variable references:

EvalStr(A & B,' ') = variable A and variable B.

Although using the variable letter codes is legal, it is best to avoid referring to variables by their codes because their location may vary.

If you wish to refer to variables, it is better to refer to them by their names using the VarCurrN and VarIndex functions. For example:

EvalStr('VarCurrN('NAME') and VarCurrN('LAST_NAME')',0)

See also:

EvalStrInfo

How Do I Construct and Evaluate an Expression at Runtime?

The Online and Rich Client Samples projects (program EX02, BS01, REX02 and RBS01)

Reference
Attachment 
Attachment