# Multiple Calculator

## Recommended Posts

Hi. I'm new with AutoIt but I'm trying hard to learn.

I try to make an multiple calculator, but I always get stuck. I don't know where I'm wrong.

Please light my way....

```#include <GUIConstantsEX.au3>
#include <GDIPlus.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <ListboxConstants.au3>
#include <ListViewConstants.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Dim \$mainwindow, \$radio_1, \$radio_2, \$radio_3, \$nr1, \$nr2, \$nr3, \$nr4, \$nr5, \$nr11, \$nr22, \$nr33, \$nr44, \$nr55
Dim \$total1, \$total2, \$total3, \$total4, \$total5, \$c_number, \$total
Local \$msg

\$mainwindow = GUICreate("Multiple Calculator", 250, 250)
GUISetState(@SW_SHOW)
\$nr1 = GUICtrlCreateInput("", 15, 30, 40, 20)
\$nr2 = GUICtrlCreateInput("", 15, 50, 40, 20)
\$nr3 = GUICtrlCreateInput("", 15, 70, 40, 20)
\$nr4 = GUICtrlCreateInput("", 15, 90, 40, 20)
\$nr5 = GUICtrlCreateInput("", 15, 110, 40, 20)
\$radio_1 = GUICtrlCreateRadio("/2", 60, 50, 40, 20)
\$radio_2 = GUICtrlCreateRadio("/3", 60, 70, 40, 20)
\$radio_3 = GUICtrlCreateRadio("/4", 60, 90, 40, 20)
GUICtrlCreateLabel("+", 100, 70, 20, 20)
\$nr11 = GUICtrlCreateInput("", 115, 30, 40, 20)
\$nr22 = GUICtrlCreateInput("", 115, 50, 40, 20)
\$nr33 = GUICtrlCreateInput("", 115, 70, 40, 20)
\$nr44 = GUICtrlCreateInput("", 115, 90, 40, 20)
\$nr55 = GUICtrlCreateInput("", 115, 110, 40, 20)
GUICtrlCreateLabel("=", 160, 70, 20, 20)
GUICtrlCreateLabel ("Results", 170 , 0, 60)
GUICtrlSetFont (-1,12,600, 4)
\$total1 = GUICtrlCreateLabel("", 190, 30, 40, 20)
\$total2 = GUICtrlCreateLabel("", 190, 50, 40, 20)
\$total3 = GUICtrlCreateLabel("", 190, 70, 40, 20)
\$total4 = GUICtrlCreateLabel("", 190, 90, 40, 20)
\$total5 = GUICtrlCreateLabel("", 190, 110, 40, 20)
\$calculate = GUICtrlCreateButton("Calculate", 10, 160, 80, 25, 0)
GUICtrlCreateLabel ("TOTAL", 100 , 160, 60)
GUICtrlSetFont (-1,12,600, 4)
\$total = GUICtrlCreateLabel("", 190, 160, 40, 20)
\$c_number = GUICtrlCreateInput("", 50, 200, 40, 20)

While 1
\$msg = GUIGetMsg()
Switch \$msg
Case \$GUI_EVENT_CLOSE
Exit

Case \$radio_1 = \$GUI_CHECKED
\$c_number = 2
Case \$radio_2 = \$GUI_CHECKED
\$c_number = 3
Case \$radio_3 = \$GUI_CHECKED
\$c_number = 4

Case \$calculate
GUICtrlSetData (\$total1, \$out)
GUICtrlSetData (\$total2, \$out)
GUICtrlSetData (\$total3, \$out)
GUICtrlSetData (\$total4, \$out)
GUICtrlSetData (\$total5, \$out)

GUICtrlSetData (\$total, \$out)
EndSwitch
WEnd```
##### Share on other sites

Try this:

```#AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d

#include <GUIConstantsEX.au3>

Global Const \$mainwindow = GUICreate("Multiple Calculator", 250, 250)

Global Const \$nr1 = GUICtrlCreateInput("", 15, 30, 40, 20)

Global Const \$nr2 = GUICtrlCreateInput("", 15, 50, 40, 20)

Global Const \$nr3 = GUICtrlCreateInput("", 15, 70, 40, 20)

Global Const \$nr4 = GUICtrlCreateInput("", 15, 90, 40, 20)

Global Const \$nr5 = GUICtrlCreateInput("", 15, 110, 40, 20)

Global Const \$radio_1 = GUICtrlCreateRadio("/2", 60, 50, 40, 20)

Global Const \$radio_2 = GUICtrlCreateRadio("/3", 60, 70, 40, 20)

Global Const \$radio_3 = GUICtrlCreateRadio("/4", 60, 90, 40, 20)

GUICtrlCreateLabel("+", 100, 70, 20, 20)

Global Const \$nr11 = GUICtrlCreateInput("", 115, 30, 40, 20)

Global Const \$nr22 = GUICtrlCreateInput("", 115, 50, 40, 20)

Global Const \$nr33 = GUICtrlCreateInput("", 115, 70, 40, 20)

Global Const \$nr44 = GUICtrlCreateInput("", 115, 90, 40, 20)

Global Const \$nr55 = GUICtrlCreateInput("", 115, 110, 40, 20)

GUICtrlCreateLabel("=", 160, 70, 20, 20)

GUICtrlCreateLabel("Results", 170, 0, 60)
GUICtrlSetFont(-1, 12, 600, 4)

Global Const \$total1 = GUICtrlCreateLabel("", 190, 30, 40, 20)

Global Const \$total2 = GUICtrlCreateLabel("", 190, 50, 40, 20)

Global Const \$total3 = GUICtrlCreateLabel("", 190, 70, 40, 20)

Global Const \$total4 = GUICtrlCreateLabel("", 190, 90, 40, 20)

Global Const \$total5 = GUICtrlCreateLabel("", 190, 110, 40, 20)

Global Const \$calculate = GUICtrlCreateButton("Calculate", 10, 160, 80, 25, 0)

GUICtrlCreateLabel("TOTAL", 100, 160, 60)
GUICtrlSetFont(-1, 12, 600, 4)

Global Const \$total = GUICtrlCreateLabel("", 190, 160, 40, 20)

GUISetState(@SW_SHOWNORMAL)

Global \$out1, \$out2, \$out3, \$out4, \$out5, \$grand_total
Global \$c_number

While True
Switch GUIGetMsg()
Case \$GUI_EVENT_CLOSE
Exit

Case \$calculate
\$c_number = 2
\$c_number = 3
\$c_number = 4
EndIf

\$out1 = (GUICtrlRead(\$nr1) / \$c_number) + GUICtrlRead(\$nr11)
GUICtrlSetData(\$total1, \$out1)

\$out2 = (GUICtrlRead(\$nr2) / \$c_number) + GUICtrlRead(\$nr22)
GUICtrlSetData(\$total2, \$out2)

\$out3 = (GUICtrlRead(\$nr3) / \$c_number) + GUICtrlRead(\$nr33)
GUICtrlSetData(\$total3, \$out3)

\$out4 = (GUICtrlRead(\$nr4) / \$c_number) + GUICtrlRead(\$nr44)
GUICtrlSetData(\$total4, \$out4)

\$out5 = (GUICtrlRead(\$nr5) / \$c_number) + GUICtrlRead(\$nr55)
GUICtrlSetData(\$total5, \$out5)

\$grand_total = \$out1 + \$out2 + \$out3 + \$out4 + \$out5
GUICtrlSetData(\$total, \$grand_total)
EndSwitch
WEnd```
Edited by LaCastiglione
##### Share on other sites

It works!!!!

Thanks a lot.

Now I hope I learn this...

Respect

Stef Ionesco

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...