Sign in to follow this  
Followers 0
Sirgijoe

Calculator Help

4 posts in this topic

Okay I am trying to put together a simple calculator tool, that has pre defined Formula's set up.

Basically I am using input boxes for the displayed numbers you want to crunch out, then it does some math in the background and puts the answer in the output box.

the problem I am having is that I can't seem to get it work as intended.

I have read the help files numerous times, watched youtube and searched google. I have found a few articles that helped me out, but every time I make a "Improvement" from what I have read online, it seems to break it even more.

the first math problem I am trying to get it to do is for lipo battery duration timers so

A = 2200 < lipo mAh >

B = 10 <Max amps pulled from Lipo at WOT >

so you take A / 1000 to get 2.2. then you take 2.2 / B to get .22

then you take .22 * 60 to get 13.2, which is how many minutes of flight I can get on a 2200 mah lipo at full throttle.

there are about 10+ more formula's I am going to add into this GUI, but if I can get the first one going, then I can see where I am doing it wrong and correct it!

here is the code

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 334, 171, 192, 124, BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX,$WS_THICKFRAME))
$Label1 = GUICtrlCreateLabel("Battery Duration Calculator", 8, 8, 320, 36, $WS_BORDER)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("Battery Capacity <mAh>", 8, 48, 121, 21)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKHEIGHT)
$Input2 = GUICtrlCreateInput("Amps pulled at max throttle", 192, 48, 137, 21)
$Output = GUICtrlCreateInput("", 104, 144, 105, 21)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKHEIGHT)
$Label2 = GUICtrlCreateLabel("Maximum minutes of flight time", 88, 120, 146, 17)
$Button1 = GUICtrlCreateButton("Calculate it!", 120, 80, 75, 25)
$Button2 = GUICtrlCreateButton("show formula", 248, 144, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $a=0, $b=0, $c=0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
     Case $Button1
calculate()
Case $Button2
Formula()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func calculate()
$Input1 = $a
$Input2 = $b
$Output = $c
GUICtrlRead($Input1)
GUICtrlRead($Input2)
$c = $a / 1000 / $b * 60
GUICtrlSetData($Output, $c)
EndFunc
Func Formula()
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text.")
EndFunc

any and all help is greatly appreciated!


The only dumb question is the one not asked!

Share this post


Link to post
Share on other sites



Try this:

Func calculate()
$a = GUICtrlRead($Input1)
$b = GUICtrlRead($Input2)
$c = $a / 1000 / $b * 60
GUICtrlSetData($Output, $c)
EndFunc ;==>calculate

Share this post


Link to post
Share on other sites

Thanks a ton! worked like a charm


The only dumb question is the one not asked!

Share this post


Link to post
Share on other sites

finished code in case anyone is interested, this will help you calculate your max flight time < for radio controlled vehicles > based off your battery size in mAh, and the max amount of amps you pull on WOT < wide open throttle >

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Battery duration calculator by Sirgijoe", 326, 168, 192, 124)
$Label1 = GUICtrlCreateLabel("Enter mAh of lipo here", 8, 8, 108, 17)
$Input1 = GUICtrlCreateInput("", 8, 32, 121, 21)
$Label2 = GUICtrlCreateLabel("Enter Max Amps pulled", 200, 8, 112, 17)
$Input2 = GUICtrlCreateInput("", 200, 32, 121, 21)
$Button1 = GUICtrlCreateButton("Calculate it!", 128, 64, 75, 25)
$Label3 = GUICtrlCreateLabel("Minutes of flight time", 112, 96, 100, 17)
$Output = GUICtrlCreateInput("", 104, 120, 121, 21)
$Button2 = GUICtrlCreateButton("Help!", 248, 136, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $a=0, $b=0, $c=0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
        Case $Button1
   calculate()
  Case $Button2
   Formula()
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd
Func calculate()
$a = GUICtrlRead($Input1)
$b = GUICtrlRead($Input2)
$c = $a / 1000 / $b * 60
GUICtrlSetData($Output, $c)
EndFunc ;==>calculate
Func Formula()
MsgBox(4096, "Help", "mAh divided by 1000 to give us amps per hour or Ah, then we take the Ah and divide that by Amps pulled to give us our hours of flight, then we multiply our hours of flight by 60 to get our total minutes of flight")
EndFunc

The only dumb question is the one not asked!

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  
Followers 0