Jump to content

Math Help Needed


Recommended Posts

I have tried diffrent variations of formulas and code for this program I am working on to help me balance my checkbook. I can't seem to get it right though.

If possible I would like the answer to the equasion to be calculated automatically when either a number in the $payment or $deposit input changes.

It would also be nice if the numbers could be rounded off for dollars and cents:

This is what I have that don't work:

$payment = GuiSetControl ("input", "", 10, 10, 50)

$deposit = GuiSetControl ("input", "", 70, 10, 50)

$balance = GuiSetControl ("input", "", 130, 10, 50)

$startbalance = GuiSetControl ("input", "", 130, 10, 50)

($balance - $payment) + $deposit = $balance

Example input: startbalance $100.00 payment $50.00 deposit $25.00 then the balance = $75.00

Any help with this is greatly appreciated....... i'm pulling my hair out

Link to comment
Share on other sites

  • Developers

Is this your actual code?

$payment = GuiSetControl ("input", "", 10, 10, 50) 
$deposit = GuiSetControl ("input", "", 70, 10, 50) 
$balance = GuiSetControl ("input", "", 130, 10, 50) 
$startbalance = GuiSetControl ("input", "", 130, 10, 50)
($balance - $payment) + $deposit = $balance

Think the result should be at the left side of the = sign:

$balance = ($balance - $payment) + $deposit

And where are you using the $startbalance field ???

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Got excited with my code finger :whistle: It should be this:

$payment = GuiSetControl ("input", "", 10, 10, 50)

$deposit = GuiSetControl ("input", "", 70, 10, 50)

$balance = GuiSetControl ("input", "", 130, 10, 50)

$startbalance = GuiSetControl ("input", "", 130, 10, 50)

($startbalance - $payment) + $deposit = $balance

Link to comment
Share on other sites

  • Developers

yes, but did you see the other comment about the result field ?

$balance = ($startbalance - $payment) + $deposit

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I have tried diffrent variations of formulas and code for this program I am working on to help me balance my checkbook.  I can't seem to get it right though. 

If possible I would like the answer to the equasion to be calculated automatically when either a number in the $payment or $deposit input changes.

It would also be nice if the  numbers could be rounded off for dollars and cents:

This is what I have that don't work:

$payment = GuiSetControl ("input", "",  10, 10, 50)     

$deposit = GuiSetControl ("input", "",  70, 10, 50)   

$balance = GuiSetControl ("input", "",  130, 10, 50)   

$startbalance = GuiSetControl ("input", "",  130, 10, 50)

($balance - $payment) + $deposit = $balance

Example input: startbalance $100.00  payment $50.00 deposit $25.00 then the balance = $75.00

Any help with this is greatly appreciated....... i'm pulling my hair out

Whatever your calculation is right or not that not the way to use GuiSetControl.

Whar you get in return is the controlref needed to read by GUIREAD($controlref) what as been typed.

I assume you start with GUICreate

define your controls with GuiSetControl

Wait the closing of the GUI with GUIWaitClose

and finally read the values with GUIRead using the $controlref of the corresponding control.

I hope that your math will be ok after that

Link to comment
Share on other sites

Sorry to say that I am still pulling my hair out over this... and I know it's not your faults. Let's start from scratch with this. Say, I create a gui that has the following qualifications:

Three input boxes

One label

I want the fist input box to be the starting balance. The second input box will be for a payment and the third for a deposit, all should be able to accept only dollar amounts and cents i.e. 100.00, 2.50 etc... The fourth element, a label will be where the remaining balance will show. The label won't be editable -it will just show the dollar amount of the equation. Now, depending on simplicity; I would like the calculations to be done as the numbers are entered but if it's too big of a deal a button to do the calculations will be fine.

What I need as a formula is this:

Starting balance minus ( - ) the payment plus ( +) the deposit will ( =) the balance

Link to comment
Share on other sites

  • When assigning a value, the variable to be assigned is always on the left of the equals sign.
  • The way you are using GuiSetControl, looks like you want to use InputBox instead
So let's try something like this:

Do
   $startbalance = InputBox("What is the starting balance?", "")
Until StringIsFloat($StartBalance) or StringIsInt($StartBalance)

Do
   $deposit = InputBox("What deposits have been made?", "")
Until StringIsFloat($Deposit) or StringIsInt($Deposit)

Do
   $payment = InputBox("What payments have been made from the account?", "")
Until StringIsFloat($Payment) or StringIsInt($Payment)

$balance = $startbalance - $payment + $deposit
Msgbox(0, "Result", "The ending balance is " & StringFormat("$%0.2f", $balance));
Edited by Nutster

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...