# A calculator

## Recommended Posts

Yeah... Im not really sure what to do and this is really buggin me because its just a calculator... It looks like this:

[C][/][*][-]

[7][8][9][+]

[4][5][6][+]

[1][2][3][E]

[ 0 ][. ][E]

Theres a little colum to the right that lists previous equations too

You type some stuff, add it, hit enter and it puts the string just fine: 126+32

But how do you solve that as a string?

I can manage sepering each equation, but I dont get how to solve the string... theres gotta be a function that does it, but I dont really know what to search for. I doubt theres a StringSolveEquation(\$sEquation) function...

calculator.bmp

##### Share on other sites

Yeah... Im not really sure what to do and this is really buggin me because its just a calculator... It looks like this:

[C][/][*][-]

[7][8][9][+]

[4][5][6][+]

[1][2][3][E]

[ 0 ][. ][E]

Theres a little colum to the right that lists previous equations too

You type some stuff, add it, hit enter and it puts the string just fine: 126+32

But how do you solve that as a string?

I can manage sepering each equation, but I dont get how to solve the string... theres gotta be a function that does it, but I dont really know what to search for. I doubt theres a StringSolveEquation(\$sEquation) function...

I'm not on a Windows box, so can't verify at the moment, but I don't think AutoIT is as picky as some languages about variable types in arithmetic operations. You can use Number() to convert the string "123" to the number 123, but I think AutoIT might give the same result for both:

\$x = "123" + "456"

\$x = 123 + 456

There's some fancy college-boy computers 101 term for that like "non-srict variable typing" or some such, but I'm not a college boy...

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

##### Share on other sites

Number()....

...

omg

LOL ok thanks that will probrably work, wow I feel so stupid right now... I need sleep

cept if i go to sleep ill sleep to long n thats not good so im staying up all night lol

##### Share on other sites

or even easier: take a look at "Eval()"

Edit: ooops. forget what I said

Edited by Marc

It's my job to comfort the disturbed and to disturb the comfortable.
My Projects: Profiler, MakeSFX, UserInfo

##### Share on other sites

Eval() is wierd... I dont understand it at all...

Dim \$a_b = 12

\$s = Eval("a" & "_" & "b") ; \$s is set to 12

?... It doesnt add anything either:

\$a = "5+12"

\$s = Eval("a")

msgbox(0,"",\$s)

returns 5+12

As for the Number() thing, Im gonna have to redo the entire calculator lol...

Omg...

Look at number example:

```\$w = Number(1+2+10);returns 13
\$x = Number("3.14");returns 3.14
\$z = Number("tmp3");returns 0```

How can you make a string into a regular ... text...?

##### Share on other sites

```MsgBox(64, @ScriptName, '5*5 = ' & _Calc('5*5'))
MsgBox(64, @ScriptName, '25+5 = ' & _Calc('25+5'))

\$expr = InputBox(@ScriptName, 'Enter a math expression...', '20*3')
MsgBox(64, @ScriptName, \$expr & ' = ' & _Calc(\$expr))

Func _Calc(\$str)
Return Execute(\$str)
EndFunc```

##### Share on other sites

Execute? I never would have thought that...

##### Share on other sites

Execute? I never would have thought that...

Grampa said "Learn something new every day."

Execute()

Cool! I'm done for day!

:-)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

##### Share on other sites

works like a charm!! thanks again u saved me alot of tweaking slim

Grampa said "Learn something new every day."

haha its 6am I guess I shouldnt look forward to learning anything else today now huh

## Create an account

Register a new account