try to substitute the parts between brackets () with the evaluation of that piece, that wouldnt be too difficult. then dividethe formula in terms that are seperated by + signs.then do so for -'s , * and /, and ^.
you could do it recursively, like:
function eval(formula$) ' now loop till(if) you find a + and then ' call the part in front part1$ and the ' other part2$ eval = eval(part1$) + eval(part2$) return eval (?? i dont know if it's necessary in QB) ' if you didnt find a + then now search ' for a - . ' and so forth. at the bottom of the function ' (in other words, when there are no non-digits ' left) use val() to evaluate the string of digits
so...it will probably look like this...
function to_get_the_brackets_gone ' the function itselfend function
function eval(formula$) if(you_find_by_looping_a_+) eval = eval(part1) + eval(part2) return eval elseif(you_find_by_looping_a_-) eval = eval(part1) - eval(part2) return eval elseif... ' the other signs (* / ^ etc)
else eval = string2number(formula$) return evalend function
function string2number(formula$) if len(formula$) = 1 then string2number = val(formula$) else string2number = 10 * string2number(left$(formula$, len(formula$) - 1)) + val(right$(formula$,1)) end if return string2numberend function
i dont know if Qb can handle recursive functions,but probably it can.
if you have any problems, dont hesitate to plant a message onthe message board. or if you want to ask something personnally, just mail.
ps: sorry about the messy way of the program, but you'll get the big picture, i hope.
if you're lucky i'll have the program ready by monday (i like the problem and i want to see if my solution works)
I 've written a little bas prg to do this, but it is only operational with proper closing marks.If you write me an e-mail I 'll try to post it back to you in a few weeks. I am interested in it too.
It looks like you're new here. If you want to get involved, click one of these buttons!