# Finding percentages

## Recommended Posts

I am making a simple VAT calculator and For some reason when I try to find 17.5% of 100 it gives me

0.7 when it should give me 17.5, here is my script so far

```#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
\$Form1 = GUICreate("VAT Calculator", 260, 265, 193, 125)
\$Label1 = GUICtrlCreateLabel("Original Number:", 8, 8, 93, 17)
\$Input1 = GUICtrlCreateInput("", 8, 32, 121, 21)
\$Label2 = GUICtrlCreateLabel("VAT:", 8, 64, 26, 17)
\$Input2 = GUICtrlCreateInput("", 8, 88, 121, 21)
\$Label3 = GUICtrlCreateLabel("VAT (Added):", 8, 120, 69, 17)
\$Label4 = GUICtrlCreateLabel("VAT (Subtracted):", 8, 176, 91, 17)
\$Input3 = GUICtrlCreateInput("", 8, 144, 121, 21)
\$Input4 = GUICtrlCreateInput("", 8, 200, 121, 21)
\$Button1 = GUICtrlCreateButton("Work Out", 8, 232, 65, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
\$nMsg = GUIGetMsg()
Switch \$nMsg
Case \$GUI_EVENT_CLOSE
Exit
case \$Button1
\$awnser = (\$Input1*0.175)
GUICtrlSetData(\$Input2, \$awnser)
EndSwitch
WEnd```

##### Share on other sites

You are currently Multiplying the control id of \$input by 0.175

Edit:

For more clarity.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

If you multiply a number by 0.175 the outcome would be the same as finding 17.5% of the number

##### Share on other sites

If you multiply a number by 0.175 the outcome would be the same as finding 17.5% of the number

You're not understanding.

1. To get a value from a GUI input control, you must use GUICtrlRead

2. If you do not use GUICtrlRead, the return value for the GUI control is it's control id

3. If you multiply your GUI Ctrl value (which in this case is 4) times 0.175 you get .7

4. To test it... you should just put a simple message box.

```#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
\$Form1 = GUICreate("VAT Calculator", 260, 265, 193, 125)
\$Label1 = GUICtrlCreateLabel("Original Number:", 8, 8, 93, 17)
\$Input1 = GUICtrlCreateInput("", 8, 32, 121, 21)
\$Label2 = GUICtrlCreateLabel("VAT:", 8, 64, 26, 17)
\$Input2 = GUICtrlCreateInput("", 8, 88, 121, 21)
\$Label3 = GUICtrlCreateLabel("VAT (Added):", 8, 120, 69, 17)
\$Label4 = GUICtrlCreateLabel("VAT (Subtracted):", 8, 176, 91, 17)
\$Input3 = GUICtrlCreateInput("", 8, 144, 121, 21)
\$Input4 = GUICtrlCreateInput("", 8, 200, 121, 21)
\$Button1 = GUICtrlCreateButton("Work Out", 8, 232, 65, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
\$nMsg = GUIGetMsg()
Switch \$nMsg
Case \$GUI_EVENT_CLOSE
Exit
case \$Button1
MsgBox(64, "info", "Your Control ID for \$Input1 is: " & \$Input1 & @CRLF & _
"Your value if you multiply your controlid * 0.175 is: " & \$Input1 * 0.175 & @CRLF & _
"Because GUICtrlRead will return a String, we will make it a number and multiply:" & @CRLF & _
\$awnser = (\$Input1*0.175)
GUICtrlSetData(\$Input2, \$awnser)
EndSwitch
WEnd```

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

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