Sign in to follow this  
Followers 0
triodz

Want to have numbers from 2 data boxes automatically add together

4 posts in this topic

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

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

  • Similar Content

    • 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
    • way1000
      By way1000
      i'm trying to create a program that let's the user type a word in an input field (gui) and when a button is pressed the letters of the word are replaced by 1 word each from a list of words in a text file
      i created the gui for it but i need help to add some more code to make it work like intented

      each letter of a word should be replaced by a word from a text file
      the text file is a source for replacing letters is a file with 2 columns separated by tab that contains the entire alphabet (26 rows)
       
      please help if possible
       
      i posted an example gui screenshot

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I'm working on a little project, and I was wondering if there's a way ( sure there is ) to insert data to a ComboBox control everytime the user insert some text in the ComboBox which is not in the ComboBox data. I'll try to explain with an example:
      - Form with some data ( ComboBox is empty );
      - User prompt something in the ComboBox: if what the user prompts is not in the ComboBox values ( at the moment empty ), then insert the value in the ComboBox values, in order to have, next time the user prompts the form, the value that he entered.
      More pratical example:
      - First call of the form, ComboBox empty;
      - I prompt "A" in the ComboBox;
      - Second call, in the ComboBox I should see "A";
      - I prompt "B" in the ComboBox;
      - Third call, I should see "A"
                                                 "B";
      - And so on...
      Everytime the form is called, I re-create it, so I think I can't use _GUICtrlComboBox_AddStrings().
      I tried with
      Global $strCboStrings = "" ; When the user prompt the form, the code below is executed. ; I.E. : User prompt "A", after the if I should have "A"; ; In the second call, If I write "B", I should see "A" ; "B"; ; If I write "A" again, in the combobox values should not be any changes. If Not StringInStr($strCboStrings, GUICtrlRead($cboVoiceCategory)) <> 0 Then $strCboStrings &= $strCboStrings & "|" & GUICtrlRead($cboVoiceCategory) EndIf Any suggestion?
      Thanks