Jump to content
Sign in to follow this  
triodz

Want to have numbers from 2 data boxes automatically add together

Recommended Posts

triodz

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.

Share this post


Link to post
Share on other sites
triodz

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

Share this post


Link to post
Share on other sites
PhoenixXL

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.

Share this post


Link to post
Share on other sites
triodz

Holy crap, that's awesome! This does exactly what I want.

Thank you so much! This is great! :D

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  

  • Similar Content

    • Jefrey
      By Jefrey
      Needed a way to store global temporary & permanent information and came up with this.
      This is inspired by NodeJS's store and store2 packages, as well as W3 specs' localStorage and sessionStorage, offering multiple ways of usage.
      This is not related to any browser's storage, nor will allow you to access or modify browsers storage - although this is possible and not a hard task, this is not what this UDF is intended to do.
      This UDF offers functions for temporary storage (that gets cleaned up once the application is shutdown) that is kept on memory using ScriptingDictionary, as well as for permanent storage, that is saved on the harddisk as an encrypted file.
      sessionStorage (temporary storage)
      It's useful to keep application state and temporary settings accessible by any part of your script (although it could also be done with a global variable, I still prefer this method).
      You have multiple ways, at your choice, to:
      ; add or modify a key sessionStorage("foo", "bar") store("foo", "bar") sessionStorage_set("foo", "bar") sessionStorage_setItem("foo", "bar") ; read a key (returns false if key does not exist) $read = sessionStorage("foo") $read = store("foo") $read = sessionStorage_get("foo") $read = sessionStorage_getItem("foo") ; delete a key sessionStorage_remove("foo") ; delete all keys sessionStorage_clear() sessionStorage_clearAll() localStorage (permanent storage)
      It's useful to store user-defined settings.
      ; initialize ; this is optional, but allows you to control ; how things are going to be saved localStorage_startup([file where you want the settings to be saved], [crypt password]) ; by default, if not supplied, if supplied the "Default" keyword (or if you dont initialize), ; the file will be a random-named file (based on @ScriptFullPath) at user's %APPDATA% ; and the password will also be based on @ScriptFullPath ; you can set only the crypt password if you want: ; localStorage_startup(Default, "mypassword") ; the usage is the same as sessionStorage ; add or modify a key localStorage("foo", "bar") store2("foo", "bar") ; notice the '2' localStorage_set("foo", "bar") localStorage_setItem("foo", "bar") ; read a key (returns false if key does not exist) $read = localStorage("foo") $read = store2("foo") $read = localStorage_get("foo") $read = localStorage_getItem("foo") ; delete a key localStorage_remove("foo") ; delete all keys localStorage_clear() localStorage_clearAll() Download
    • oceanwind
      By oceanwind
      Hi All:
       How to set the input border color?
      tks in advance
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys this is my gui and i need the numeric value typed in the highlighted  inputbox. if this value is greater than 1 i need to perform some operations
      \
       
      Here is the summary about that field which i got from wininfo tool

      i tried writing the code as shown below.. but the msgbox is popping up empty value..when the same code is pasted under some button action i am able to access the value present in the field..but when placed alone as written in the attached script i am unable to fetch it... 

      here i am using the valu present in the field

      can you guys tell me what's wrong??? or how can i get that value?
       
      My_GUI.au3

    • Shirdish_chakravarthi
      By Shirdish_chakravarthi

      in need the path/text present int above shown input box to be copied or retrieved into a variable .. how can i do that?
       
      Thanks
       
    • Seminko
      By Seminko
      Hey,
      i would like to set a value into an INPUT field.
      Checked the _IEFormElementSetValue function but that does require _IEFormGetObjByName and this is where the problem comes in. The input field I want to write to is not a part of a form tag. It is part of a table.
      <input type="text" class="w2" id="nabidka_vozidel_formular_tach_od" name="nabidka_vozidel_formular_tach_od" onchange="GLOBAL.pocetInzerceNZ(&quot;nabidka_vozidel_formular&quot;,&quot;tach_od&quot;,&quot;&quot;);" autocomplete="off"> I tried this but that didn't work:
      $oDownloadSamples = _IEGetObjById($oIE, "nabidka_vozidel_formular_tach_od") _IEFormElementSetValue($oDownloadSamples, "123") If you want to try the site I'm working with is https://www.tipcars.cz/. There is a menu on the top left hand side and if you click the "vyhledat" button the input fields will show up.
      Thanks
×

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.