Jump to content

What is the best way to check and collect changed input values?

Recommended Posts

Here is an example script:

I have inputs with default values (e.g names) 

What is the cleanest code and most simple way,  that can collect the input values changed from default?

What do you think are there any more solution, that is better?

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 437, 593, 222)

$Value1 = "Sample Name 1"
$Value2 = "Sample Name 2 "
$Value3 = "Sample Name 3"
$Value4 = "Sample Name 4"
$Value5 = "Sample Name 5"
$Value6 = "Sample Name 6"

$Input1 = GUICtrlCreateInput($Value1, 200, 40, 121, 21)
$Input2 = GUICtrlCreateInput($Value2, 200, 72, 121, 21)
$Input3 = GUICtrlCreateInput($Value3, 200, 104, 121, 21)
$Input4 = GUICtrlCreateInput($Value4, 200, 136, 121, 21)
$Input5 = GUICtrlCreateInput($Value5, 200, 168, 121, 21)
$Input6 = GUICtrlCreateInput($Value6, 200, 216, 121, 21)
$Button = GUICtrlCreateButton("Save",200,250,50,50)
#EndRegion ### END Koda GUI section ###

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

Func ButtonSave()

    Local  $WichInputs[110]
 $SomethingChanged = False
If GUICtrlRead($Input1) <> $Value1  Then
    $SomethingChanged = True
ElseIf GUICtrlRead($Input2) <> $Value2  Then
        $SomethingChanged = True
ElseIf GUICtrlRead($Input3) <> $Value3  Then
        $SomethingChanged = True
    ElseIf GUICtrlRead($Input4) <> $Value4  Then
        $SomethingChanged = True
    ElseIf GUICtrlRead($Input4) <> $Value4  Then
        $SomethingChanged = True
    ElseIf GUICtrlRead($Input5) <> $Value5  Then
        $SomethingChanged = True
        ElseIf GUICtrlRead($Input6) <> $Value6  Then
        $SomethingChanged = True


If $SomethingChanged == True Then
    MsgBox(0,"Changed","chenges FROM TO" & _ArrayToString($WichInputs,@TAB)  )
    MsgBox(0,"No","No chenges")



Link to post
Share on other sites
Posted (edited)

Put all your input controls into an array and your original value as well.  Then loop thru the arrays to find a difference.

Another approach is to register WM_COMMAND message and check for EN_CHANGE code.  This will allow you to check for every single character changes.

Edited by Nine
Link to post
Share on other sites

Agree with @Nine, put the controls in an array and loop thru them performing basically the same checking you did in the code you provided.

Btw, whenever you start writing code like "If $thing1 then... If $thing2 then... If $thing3 then..." you should recoil and consder using an array if possible.  You could also use a database or even dynamically generate code, but for something like this the array seems easiest.

Once you start down the thing1, thing2 path though, the chances of a copy and paste error increase greatly, even when one is careful.

For instance, in your posted code:

ElseIf GUICtrlRead($Input4) <> $Value4  Then
        $SomethingChanged = True
    ElseIf GUICtrlRead($Input4) <> $Value4  Then
        $SomethingChanged = True


Code hard, but don’t hard code...

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...