This content has been marked as final. Show 7 replies
I don't know (maybe I've missed something) an easy way to parse a string (which is what you have from your component parameter) like that to evaluate. But I think so long as you have a limited set of boolean operators, then the following approach should work. Note you will need to code in some error condition handlers.
It works!!!! THANKYOU, THANKYOU , THANKYOU ,THANKYOU THANKYOU
Once i have worked out what you have done...i will try and get it to work
for more than two operands....that's fantastic, and i really appreciate your
assistance Hadgy, u r a legend!!
It is a pity that you can't just read the boolean statement straight in and
have the function execute it....it seems like a lot of effort to get around
it but hey.....it works!!!!
whoops my praise was meant for GWD.....not hadgy :)
You're welcome. Perhaps there's an easier way, but I can't think of one.
1. Checks through the string ("a||b" or whatever it is), looking for known boolean comparison operators - whatever is listed in the BoolTestOperators array. You can add to this... e.g. ">=" for example. The index of the operator that is found is i
2. Splits the string into an operands array by using the operator string as the delimiter. So the array should normally always have 2 elements, whatever was before the operator and whatever was after it.
3. determines the function that will be used based on the operator string that was found. Here I have a function that takes the operator string as a parameter and returns a function based on a switch/case block. The function that is returned always takes a single parameter which is an array (in this case it should always be an array of 2 operands).
Its pretty easy to extend this if you just copy the case ...break; sections and change how the two operands are compared. E.g. you could put >= or whatever.
Thanks for the description. I think i've got that now. I can see why i was
taking so long to work it out.....I was totally on the wrong track and
probably wouldn't have got there!!!
Really appreciate your time. Thanks.
No problems. If a and b will be something other than boolean values (true/false 1/0 for comparisons) then will have to change things... you should probably remove all the Boolean() parts of the return function... maybe they weren't necessary.
E.g. if you want to compare a=20 with b=4 and do a greater than comparison, you don't want a and b being converted to boolean values first. Otherwise it would be true > true which I think is the same as 1 > 1 which is false.