Jump to content
Sign in to follow this  
triodz

Want to have numbers from 2 data boxes automatically add together

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.

Share this post


Link to post
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

Share this post


Link to post
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.

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

    • By nacerbaaziz
      good morning sirs.
      please i have a request from you.
      i have an variable to Read a data from a file
      this data is Encrypted
      and when i read it i Decrypte it.
      for that i need a function to Write a ini data to string.
      ;#Function# ===================================================================================================================== ; Name............: _IniReadFromString ; Description.....: Returns the value of a key in a specific section of an ini-formatted string ; Syntax..........: _IniReadFromString($szInput, $szSection, $szKey, $Default) ; Parameters......: ;   $szInput - The string that contains data in ini format ;   $szSection   - The sectionname (just as in IniRead) ;   $szKey   - The keyname (just as in IniRead) ;   $Default - The default value if the key does not exist or reading failed (just as in IniRead) ; Return values ..: ;   Success  - Returns the read value ;   Failure  - Returns $Default ; Author .........: FichteFoll ; Remarks ........: Works for Unicode as well as for ANSI ; Related ........: IniRead, _IniReadSectionFromString ; Link ...........; See on top ; Example ........; $var = _IniReadFromString(StringFormat("[Sect]\r\nMyKey1=value1\r\nMyKey2=value2"), "Sect", "MyKey2", "no_value") ; =============================================================================================================================== Func _IniReadFromString($szInput, $szSection, $szKey, $Default) $szInput = StringStripCR($szInput) ;~  Local $aRegMl = StringRegExp($szInput, "\[" & __StringEscapeRegExp($szSection) & "\]\n+(?:[^\[].*?=.*\n)*" & __StringEscapeRegExp($szKey) & "=(.*)\n?(",3) Local $aRegMl = StringRegExp($szInput, "\[" & __StringEscapeRegExp($szSection) & "\]\n+(?:[^\[].*?=.*\n)*" & __StringEscapeRegExp($szKey) & "=(.*)\n?", 3) If @error Then Return SetError(1, 0, $Default) ; key not found    Return $aRegMl[0] EndFunc;==>_IniReadFromString ; ############################################################################################################################### ; =============================================== ; = Internal Use Only ; =============================================== Func __StringEscapeRegExp($szExp) Return StringRegExpReplace($szExp, "([\(\)\[\]\{\}\\\/\?\.\\|\+])", "\\$1") ; ()[]{}\/?.|+ EndFunc;==>__StringEscapeRegExp like this  function Read the ini from string.
       
       
      please ihelp me
      thanks in advance
    • By Rhidlor
      I don't have any experience compiling AutoIt scripts or know of any best practices regarding said scripts so I was wondering, what are some of the options for passing data to complied scripts? Here's an example of what I mean by "option": Writing data to a text file, then running a script which reads the data from that text file.
      Thanks!
      I apologize if this topic is a little lackluster
    • By Blueman
      Hey Guys,
      Maybe you can help me with something small.
      It is not terrible but it slows down my script and after a while even crash the script.

      First i explain what i have;
      I have a GUI with a lot of GUICtrlCreateInput controls, lets say 600 pieces.
      All the controls are hidden when the GUI is displayed, i have 3 buttons attached to 200 pieces each.
      When i press button-1 the first 200 controls are showed,
      When i press button-2 the first 200 controls are hidden and the next 200 controls are showed,
      etc, etc.
      This is working perfectly but after a while the GUI is getting slower and slower.
      After a while the controls aren't responding anymore and the script crashes.
      When i compile the script to 64-Bits version the speed is a lot better but you can still see the script slowing down each time i use the buttons.
      I think there has to be a buffer somewhere that is filling each time i show and hide the controls, but how can i clear that buffer without restarting the script?
      Deleting and re-creating the controls didn't help, deleting the entire gui (and controls) and re-creating it didn't help also.
      The only thing that is working is restarting the script.

      Thanks guys!

      PS: If you need a working example i can add it to this topic, just let me know. It is not rocket science, i just create the controls and show/hide them with a while loop and 3 buttons.
       
    • By XinYoung
      Hello again 
      I need to click this Submit button, but it's in a lightbox and has no ID (i think) and I can't figure out a way to target it. _IEFormSubmit doesn't work.

       
      Thank you
    • By Lisuter
      Hello...

      How i can write data from txt to +3 Input?
      Example:
      In txt i have:
      Michael XYZ, 21, Boston
      Olex Marshal, 17, Boston
      Alex XYZ, 19, Boston
       
      And now i want load that data to input in autoit. 

      Name          y.o          city
      [ Input1]  [Input2] [Input3]
      [ Input4]  [Input5] [Input6]
      [ Input7]  [Input8] [Input9]
       
      After load should be:
      Name               y.o            city
      [Michael XYZ]      [21]     [Boston]
      [ Olex Marshal]  [17]      [Boston]
      [ Alex XYZ]           [19]      [Boston]
       
      FileOpen("Test.txt",0)                          $aas = GUICtrlSetData($Input1, FileReadLine("Test.txt",1))             FileClose("Test.txt") But its wrong. ofcourse its load all to input 1. So now how do you load this data directly into each input separately? The comma stop sign is here. Each line is a new person
×
×
  • Create New...