Re: How, using I4GL, do you evaluate a numerical expression held in a CHAR variable
Posted in 1998
Paul Wheeler wrote: > > Does anybody remember the 'EVAL' command in Basic? It allows you to > compose a > string variable, e.g. A$="((127-82)/42)*27.5" and then assign the value of > the string into > a numeric variable, i.e. A=EVAL(A$). > > Currently I am using a SQL query to do this calculation for me and it is > proving inefficient. > I'm sure there is a 'text box' answer for this solution, something along > the lines of calling a function > with a pre-constructed string, and for it to return the evaluated answer > with a level of decimal > precision. > > Any ideas would be gratefully appreciated. > > Paul Wheeler. There is no way to do this in 4GL. BASIC does it partly because it is an interpreter: the EVAL function uses the part of the interpreter that handles expressions. 4GL is a compiler and has no function to do this. The database engine contains an SQL interpreter, which is what you use to evaluate expressions. I can imagine it would be rather slow. Another possible method would be to use the Unix bc calculator via a pipe. I too had this requirement and wrote an expression compiler and stack machine using yacc and lex, which I linked into an ESQL/C program. It's not a trivial undertaking. I believe you can embed the tcl interpreter in your own code; that might be a quicker way to go. -- Peter Lancashire Information Systems Specialist, Bayer plc Eastern Way, Bury St Edmunds, Suffolk, IP32 7AH, UK Tel: +44-1635-562258, Fax: +44-1635-562281 Mail: Peter.Lancashire.PL1@bayer.co.uk --- My Internet plumbing does not allow me to mail and post news together. Sorry. All opinions are my own and not those of Bayer plc. --- Join Infuse, the UK Informix User Group at http://www.infuse.org.uk/