Eval() Equivalent for Progress

Timjr56

New Member
Hello There,

I was just curious if there is an equivalent function in progress much like the javascript function eval();

I have a variable that is going to hold a table and a field name:

Def var x as character no-undo.
x = "customer.cust-no".

and when i loop through the customer's, i want the actual customer number to be displayed instead of "customer.cust-no".

Note: This is just an example of what I am wanting, not exactly what I'm using it for. I have a Label Generator and the information that is to be displayed on this label is to be dynamic, so I was thinking to just hold the table/field name of field i want to use.

If there isn't a function (or procedure) to do this, what would be a suggestion(s) to accomplish this?

Thanks in advance for your help.

Tim
 

LarryD

Active Member
AFAIK there isn't any specific function other than REPLACE.

For your example (assuming that customer.cust-no is a char field):

Code:
def var x as character format "x(20)" no-undo.
 x = "customer.cust-no".

display replace(x,"customer.cust-no",customer.cust-no).

If a number:
Code:
def var x as character format "x(20)" no-undo.
 x = "customer.cust-no".

display replace(x,"customer.cust-no",trim(string(customer.cust-no))).
 

rstanciu

Member
/* dynaMathExpression.p */

DEFINE VARIABLE cExpression AS CHARACTER NO-UNDO.
DEFINE VARIABLE dResult AS DECIMAL NO-UNDO.
DEFINE VARIABLE lResult AS LOGICAL NO-UNDO.
DEFINE VARIABLE cResult AS CHAR NO-UNDO.

DEFINE TEMP-TABLE tt NO-UNDO /*dummy TT*/
FIELD f1 AS INTEGER.
DEF QUERY q FOR tt. /* dummy query, but required */

FUNCTION GetDecimal RETURNS LOGICAL
(INPUT dValue AS DECIMAL).
dResult = dValue.
RETURN TRUE.
END FUNCTION.

FUNCTION GetChar RETURNS LOGICAL
(INPUT cValue AS CHAR).
cResult = cValue.
RETURN TRUE.
END FUNCTION.

FUNCTION GetLogical RETURNS LOGICAL
(INPUT lValue AS LOGICAL).
lResult = lValue.
RETURN TRUE.
END FUNCTION.

/*Evaluate a 4GL decimal expression */
cExpression = "2 + 3.141592654 * 4".
QUERY q:QUERY-PREPARE("FOR EACH tt WHERE ~
DYNAMIC-FUNCTION( 'GetDecimal', " + cExpression + ") = TRUE").
QUERY q:QUERY-OPEN().
QUERY q:QUERY-CLOSE.
MESSAGE dResult VIEW-AS ALERT-BOX INFO BUTTONS OK.

/*Evaluate a 4GL character expression */
cExpression = "'ab' + 'cd '
+ replace('HELLO user-name','user-name','PROGRESS WORLD !')".
QUERY q:QUERY-PREPARE("FOR EACH tt WHERE ~
DYNAMIC-FUNCTION( 'GetChar', " + cExpression + ") = TRUE").
QUERY q:QUERY-OPEN().
QUERY q:QUERY-CLOSE.
MESSAGE cResult VIEW-AS ALERT-BOX INFO BUTTONS OK.

/*Evaluate a 4GL logical expression */
cExpression = "IF 2 + 2 = 4 THEN YES AND (yes OR NO) ELSE 2 + 2 = 4".
QUERY q:QUERY-PREPARE("FOR EACH tt WHERE ~
DYNAMIC-FUNCTION( 'GetLogical', " + cExpression + ") = TRUE").
QUERY q:QUERY-OPEN().
QUERY q:QUERY-CLOSE.
MESSAGE lResult VIEW-AS ALERT-BOX INFO BUTTONS OK.
 
Top