Page 1 of 1

2+2

Posted: Mon Aug 01, 2011 7:32 pm
by gg4000
Hi

I'm trying to send 2+2 to a spreadsheet or anything to return a sum "4". or "2+2=4"
It's from a textbox in my calculator program. The textbox will contain the whole string "2+2"
I can add sum( or = within the program after a button click. I will also have multiply, divide, minus...etc.
The sheet will not be open. I just need to do the math as one input. ex. 2+2...

Any ideas?

Thank you

Re: 2+2

Posted: Tue Aug 02, 2011 4:00 am
by Apollo
Try this: (note the preceding = character)

Code: Select all

=2+2

Re: 2+2

Posted: Tue Aug 02, 2011 4:45 pm
by gg4000
How and where to send it to be processed is my problem.

Re: 2+2

Posted: Tue Aug 02, 2011 9:23 pm
by Christopher
So you want to parse strings like "2+2" or "3/4" or 5*6" and then calculate the result? I would recommend preg_match() or preg_split().

Re: 2+2

Posted: Wed Aug 03, 2011 6:15 am
by gg4000
Right. I was able to split the text. But don't know what to do with it then. If I was able to put the number or numbers before the + into one hidden textbox and the number after the + into another, then I could process the two text boxes in my program. textbox1.text + textbox2.text.

Re: 2+2

Posted: Wed Aug 03, 2011 10:28 am
by AbraCadaver
Apollo wrote:Try this: (note the preceding = character)

Code: Select all

=2+2
If you are putting this in a spreadsheet then something like this after you have received the posted form:

Code: Select all

$calc = '=' . $_POST['formfieldname'];
Then put $calc in the spreadsheet cell. Or maybe I am totally misunderstanding?

Re: 2+2

Posted: Wed Aug 03, 2011 4:02 pm
by Christopher
gg4000 wrote:Right. I was able to split the text. But don't know what to do with it then. If I was able to put the number or numbers before the + into one hidden textbox and the number after the + into another, then I could process the two text boxes in my program. textbox1.text + textbox2.text.
You will receive the text "2+2" as a string. When you split it you will have variables or an array like (array('2', '+', '2'). You will then need to walk through the array and do the computation based on the values and operators. It is a state machine.