Jump to content

Want to have numbers from 2 data boxes automatically add together


triodz
 Share

Recommended Posts

This probably has a simple solution, but I cannot figure it out. First here is the code:

#include
#include
#include
#include
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("", 234, 58, 192, 124)
$FIRST = GUICtrlCreateLabel("First", 8, 16, 23, 17)
$SECOND = GUICtrlCreateLabel("Second", 104, 15, 41, 17)
$1st=GUICtrlCreateInput("", 36, 12, 57, 21)
$2nd=GUICtrlCreateInput("", 150, 12, 57, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$FIRST1=GUICtrlRead($1st)
$SECOND2=GUICtrlRead($2nd)

if $FIRST1<>"" Then
$SECOND2=$FIRST1+$SECOND2
EndIf

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd

What I want to do is, when I put a number in the First inputbox, the Second inputbox automatically adds it to its total.

Example:

First: I put in the number 6

Second: It already has the number 8 in it

I want the Second to automatically update to 14.

Any help is greatly appreciated.

Link to comment
Share on other sites

Well, I figured out a way around it... sorta. I will be using this to keep track of numbers. So the last number entered needs to be added to the new number entered.

I ended up with a msgbox that pops up with the current total. I would prefer this to show in an inputbox if this possible though.

For anyone interested:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 211, 85, 192, 124)
$FIRST = GUICtrlCreateLabel("First", 8, 16, 23, 17)
$1ST=GUICtrlCreateInput("", 36, 12, 57, 21)
$Button1 = GUICtrlCreateButton("Add", 20, 40, 75, 25)
$Button2 = GUICtrlCreateButton("Clear", 104, 40, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$FIRST1=GUICtrlRead($1st) ;reads number entered
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   FileDelete("total.txt") ;deletes any created files so there is no interference next time
   Exit
  Case $Button1
   $LASTTOTAL=FileReadLine("total.txt",-1) ;reads last number in tally file. If not there, it is created
   $NEXTTOTAL=$FIRST1+$LASTTOTAL ;adds the last number in the tally file with the number entered in inputbox
   $TOTALFILE=FileWriteLine("total.txt",$NEXTTOTAL) ;writes new total in tally file
   MsgBox(1,"",$NEXTTOTAL) ;displays the current total
  Case $Button2
   FileDelete("total.txt") ;deletes the tally file if you want to start again
EndSwitch
WEnd
Link to comment
Share on other sites

This is probably a better approach

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>


GUICreate("Form1", 211, 85, 192, 124)
Global $Inpt_1 = GUICtrlCreateInput("", 36, 12, 57, 21, $ES_NUMBER)
Global $Inpt_2 = GUICtrlCreateInput("", 36, 44, 57, 21, $ES_NUMBER)
GUIRegisterMsg ( $WM_COMMAND , 'WM_COMMAND' )
GUISetState(@SW_SHOW)


While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

Func WM_COMMAND ( $hWnd, $iMsg, $wParam, $lParam )
$nTfctn = _WinAPI_HiWord( $wParam )
If $nTfctn <> $EN_CHANGE Then Return $GUI_RUNDEFMSG
$nID = _WinAPI_LoWord ( $wParam )
Switch $nID
Case $Inpt_1
GUICtrlSetData ( $Inpt_2, GUICtrlRead($Inpt_1) + GUICtrlRead($Inpt_2))
Return 0
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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

×
×
  • Create New...