Jump to content
Sign in to follow this  
Walls192

Finding percentages

Recommended Posts

Walls192

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 this post


Link to post
Share on other sites
SmOke_N

(Number(GUICtrlRead($Input1))*0.175)

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

Edit:

Added: You are currently,

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 this post


Link to post
Share on other sites
Walls192

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

Share this post


Link to post
Share on other sites
SmOke_N

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 & _
                "(Number(GUICtrlRead($Input1))*0.175) = " & (Number(GUICtrlRead($Input1))*0.175))
            $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.

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.