I have a variable string containing a logic expression.
I want a way to evaluate this variable to find out the result of the expression. Has any function that allows me to do this?
Example:
Define variable cExpression As Character No-undo.
Assign cExpression = "true or false" .
I´d like to get the value of the logical expression...is it possible?
Thank you,
Éllen
I don't really get your example of "true or false". That is kind of meaningless.
I assume you mean something more like one of the following:
cExpression = "myInt > 5".
cExpression = "myInt = 5 OR mycc = "ABC".
No - there is nothing in the language that will take a logical expression as a string and evaluate it.
But there is a trick - knowledgebase.progress.com/.../P39990
Create a dummy temp-table with 1 record.
Create a query dynamically on this temp table.
Parse your expression in the prepare string of the query.
Something like "for each tt where true or false" or "for each tt where 3 + 2 > 5".
In the latter you can you can replace the 2 with the value of a variable for example substitue("for each tt where 3 + &1 > 5", variable) and suddenly you have run time evaluation.
Check availbilty of tt record or query result, to see if evaluation is true.
That's in short the knowledgebase entry. Took me some time to crasp.
Flag this post as spam/abuse.
That is TRUE if the expression is a CHARACTER expression. The LOGICAL function is converting a String to a Logical. But you can also do:
MESSAGE LOGICAL(TRUE AND FALSE). >> no
MESSAGE LOGICAL(FALSE OR TRUE). >> yes
MESSAGE LOGICAL(7 < 1000). >> yes
The intent of LOGICAL is to do type conversion to YES/NO based on string values. So.
MESSAGE LOGICAL ("Femme", "Homme/Femme") >> no
>> MESSAGE LOGICAL ("Femme", "Homme/Femme") >> no
That is TRUE if the expression is a CHARACTER expression. The LOGICAL function is converting a String to a Logical. But you can also do:
MESSAGE LOGICAL(TRUE AND FALSE). >> no
MESSAGE LOGICAL(FALSE OR TRUE). >> yes
MESSAGE LOGICAL(7 < 1000). >> yes
The intent of LOGICAL is to do type conversion to YES/NO based on string values. So.
MESSAGE LOGICAL ("Femme", "Homme/Femme") >> no
Flag this post as spam/abuse.
When it comes to evaluation on the fly, the trick of P39990 rules. An amazing trick that can evaluate something like "2 + 3 * 4" with the right operator precedence (that is indeed 14 and not 20)
Thank you so much!