Page 2 of 3

Posted: Thu Jun 30, 2005 7:01 pm
by DarkDragon
utopiomania wrote:Daniel, it handles any number of variables up to #MAXVARS, and you can use long variable
names if you like.
But it just returns one result for 2 variables O_o which var is it then?

Posted: Thu Jun 30, 2005 7:46 pm
by utopiomania
It isn't case sensitive if that's what you mean ?, so O and o is the same variable, just like variables in PureBasic.
Hope I understood you right.

Posted: Thu Jun 30, 2005 7:47 pm
by Justin
Very cool. maybe this could be used for this?,

in an ADO recordset there is a filter property that accepts an expression, but the syntax is limited, from the docs:

Code: Select all

There is no precedence between AND and OR. Clauses can be grouped within parentheses. However, you cannot group clauses joined by an OR and then join the group to another clause with an AND, like this: 
(LastName = 'Smith' OR LastName = 'Jones') AND FirstName = 'John'

Instead, you would construct this filter as 
(LastName = 'Smith' AND FirstName = 'John') OR (LastName = 'Jones' AND FirstName = 'John')
so the function would take a complex expression like the first one and translate it to the second one, handling all nesting levels. How difficult would be?

Here's the complete description for the filter property,

Code: Select all

Use the Filter property to selectively screen out records in a Recordset object. The filtered Recordset becomes the current cursor. Other properties that return values based on the current cursor are affected, such as AbsolutePosition, AbsolutePage, RecordCount, and PageCount. This is because setting the Filter property to a specific value will move the current record to the first record that satisfies the new value.

The criteria string is made up of clauses in the form FieldName-Operator-Value (for example, "LastName = 'Smith'"). You can create compound clauses by concatenating individual clauses with AND (for example, "LastName = 'Smith' AND FirstName = 'John'") or OR (for example, "LastName = 'Smith' OR LastName = 'Jones'"). Use the following guidelines for criteria strings: 

FieldName must be a valid field name from the Recordset. If the field name contains spaces, you must enclose the name in square brackets. 
Operator must be one of the following: <, >, <=, >=, <>, =, or LIKE. 
Value is the value with which you will compare the field values (for example, 'Smith', #8/24/95#, 12.345, or $50.00). Use single quotes with strings and pound signs (#) with dates. For numbers, you can use decimal points, dollar signs, and scientific notation. If Operator is LIKE, Value can use wildcards. Only the asterisk (*) and percent sign (%) wild cards are allowed, and they must be the last character in the string. Value cannot be null. 
Note   To include single quotation marks (') in the filter Value, use two single quotation marks to represent one. For example, to filter on O'Malley, the criteria string should be "col1 = 'O''Malley'". To include single quotation marks at both the beginning and the end of the filter value, enclose the string with pound signs (#). For example, to filter on '1', the criteria string should be "col1 = #'1'#". 

There is no precedence between AND and OR. Clauses can be grouped within parentheses. However, you cannot group clauses joined by an OR and then join the group to another clause with an AND, like this: 
(LastName = 'Smith' OR LastName = 'Jones') AND FirstName = 'John'
Instead, you would construct this filter as 
(LastName = 'Smith' AND FirstName = 'John') OR (LastName = 'Jones' AND FirstName = 'John')
In a LIKE clause, you can use a wildcard at the beginning and end of the pattern (for example, LastName Like '*mit*'), or only at the end of the pattern (for example, LastName Like 'Smit*'). 

Posted: Thu Jun 30, 2005 8:14 pm
by utopiomania
Justin, I'm shure it can be used for this. The simplest would probably be to write a
procedure to walk through the expression string and replace all FieldName-Op-Value's
with a 1 for True and 0 for a False, then let Eval() solve it:

"(LastName = 'Smith' OR LastName = 'Jones') AND FirstName = 'John'" is translated to:
"(1 OR 0) AND 1" which is then solved by Eval(). :)

Posted: Thu Jun 30, 2005 10:50 pm
by Justin
that should work but would require to filter the recordset programatically by me, i was thinking in an expression translator that accepts a string like,

(LastName = 'Smith' OR LastName = 'Jones') AND FirstName = 'John'

and returns a string,

(LastName = 'Smith' AND FirstName = 'John') OR (LastName = 'Jones' AND FirstName = 'John')

so it can be used by the filter property and lets the ado engine do the work, looks a bit complex.

Posted: Fri Jul 01, 2005 8:56 am
by DarkDragon
utopiomania wrote:It isn't case sensitive if that's what you mean ?, so O and o is the same variable, just like variables in PureBasic.
Hope I understood you right.
Noooo, here a short equation:

0=x^2+x-5

There it should give me 2 results:

x1/2 = -0.25+-sqr(0.25+5)
x1 = 2.04 ;Result 1
x2 = -2.54 ;Result 2

Or this one:

1) y=x+5
2) y=2x-5
---
2x-5 = x+5 | +5
2x = x+10 | - x
x = 10
---
y = 10+5
y = 15

Result = (10|15)

Posted: Fri Jul 01, 2005 11:47 am
by utopiomania
Oh, I see. The parser solves expressions, not equations.

Posted: Sat Jul 02, 2005 10:03 am
by Justin
utopiomania, can you add string support? i'll try to do the ado filter, making a LIKE command should be easy and it could even have a regexp command REG, there is a com object that evaluates regular expressions, and a NULL keyword for values to match empty fields.

Posted: Wed Jul 06, 2005 8:34 pm
by utopiomania
Justin, I don't know if I can add string support, but I have to tell you I have too much
work to do on my own petty projects already, so I can't say yes or no.

Sorry for my late answer, but I'm on holiday now, and just managed to log on to the net
using my laptop and my Moto V600, at 9.6kbits a sec... Sloooow and expensive, so I have
to keep it short for the next week and a half. :)

Posted: Wed Jul 06, 2005 9:50 pm
by Justin
i have already added string support and turned it into a custom eval object where you set the ops to use etc.. needs still a little more work, then i'll post it

Posted: Mon Aug 29, 2005 8:02 pm
by ricardo
Justin wrote:i have already added string support and turned it into a custom eval object where you set the ops to use etc.. needs still a little more work, then i'll post it
Great!!

Any posibility to see the code? :D

Posted: Mon Aug 29, 2005 8:12 pm
by thefool
very nice code!

Posted: Tue Aug 30, 2005 8:54 am
by Flype
even if there are some improvements to do, it's a nice & clean parser, thanx.

@utopiomania:
Eval("(23).56")
Eval("23___56")

...should return ERR_SYNTAX, no ?

Posted: Wed Aug 31, 2005 9:43 pm
by utopiomania
thefool and Flype, Thanks for your comments. :)
...should return ERR_SYNTAX, no ?
Of course it should have. :wink:

Posted: Sun Feb 11, 2007 12:26 pm
by utopiomania
I was about to include this in a program compiled to unicode, so I've just updated it to PB4.00.

The original console mode demo didn't work in unicode, so I removed it for the post. The evaluator
itself works in unicode though.