Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I analsys a expression

Status
Not open for further replies.

viettla

Programmer
Jul 19, 2002
34
VN
Hi all,
Im building a APP that users can make expression from fields. Now it's my problem, How can I analsys a expression to fields name, constants and operators
Could you point me about a algorithm please ?
Thank you very much

Viet
 
Build an expression builder your user(s) can use to build the expressions and you can control the syntax of the expression.

Rob.
 
Rob,
Thank for your help
But I built an expression builder myself. I used caption instead of field name so I need analsys expression for solving nest expression (expression in expression)


Viet
 
viettla

It is unclear what you are trying to achieve, what do you mean by "so I need analsys expression for solving nest expression (expression in expression)"



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,
Im sorry about my English
My app allow users can define a field as a calculated field or an expression I need to parse that expression. Which does expression include fields name, constants , operators and other expression ?
How can I do this ?
thank's alot

Viet
 
Hi viettla,

If I understand you correctly, you have to make a lot of DO..CASE, or you can use table and put in every expression that will be used by user.

This code is just for a starter (you need a LOT more code than this)

cExpression = This.Value
If !empty(cExpression)
nError = 0
On error nError = error()

= evaluate(cExpression) && test the expression
If (nError == 1300) && something wrong in expression
cExpression = alltrim(cExpression) + ')'
nError = 0
= evaluate(cExpression)
endif

If (nError == 0)
*** Check the expression against the table
* ...
*
If (nError == 0)
nValue = evaluate(cExpression)
endif
endif

On error
endif

Hope it helps a little

-- AirCon --
 
As a suggestion, use a delimiter in the expression around each field description, something like:


[Unit Price] * [Quantity Bought] * ([Sales Tax Percent] + 1)

Then, you can simply SCAN through a table that lists the fields, or hard code the fields, like this (assuming lcExpr contains the above pseudo-expression):

Code:
lcVFPExpr = lcExpr
lcVFPExpr = STRTRAN(lcVFPExpr,'[Unit Price]', 'orderTable.UnitPrice')
lcVFPExpr = STRTRAN(lcVFPExpr,'[Quantity Bought]', 'orderTable.Qty')
lcVFPExpr = STRTRAN(lcVFPExpr,'[Sales Tax Percent]', '0.06')

Then you can check if it's valid:

IF TYPE(lcVFPExpr)='N'
* Yup, It's valid!!
ENDIF

and just use macro replacement or EVAL() to evaluate it:

lnAmt = &lcVFPExpr
* or
lnAmt = EVAL(lcVFPExpr)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top