DannyJ Posted May 17, 2021 Share Posted May 17, 2021 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? expandcollapse popup#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) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button ButtonSave() EndSwitch WEnd Func ButtonSave() Local $WichInputs[110] $SomethingChanged = False If GUICtrlRead($Input1) <> $Value1 Then $SomethingChanged = True _ArrayAdd($WichInputs,$Input1) ElseIf GUICtrlRead($Input2) <> $Value2 Then $SomethingChanged = True _ArrayAdd($WichInputs,$Input2) ElseIf GUICtrlRead($Input3) <> $Value3 Then $SomethingChanged = True _ArrayAdd($WichInputs,$Input3) ElseIf GUICtrlRead($Input4) <> $Value4 Then $SomethingChanged = True _ArrayAdd($WichInputs,$Input4) ElseIf GUICtrlRead($Input4) <> $Value4 Then $SomethingChanged = True _ArrayAdd($WichInputs,$Input4) ElseIf GUICtrlRead($Input5) <> $Value5 Then $SomethingChanged = True _ArrayAdd($WichInputs,$Input5) ElseIf GUICtrlRead($Input6) <> $Value6 Then $SomethingChanged = True _ArrayAdd($WichInputs,$Input6) EndIf ;-DISPLAY CHANGED VALUES If $SomethingChanged == True Then MsgBox(0,"Changed","chenges FROM TO" & _ArrayToString($WichInputs,@TAB) ) Else MsgBox(0,"No","No chenges") EndIf EndFunc Link to comment Share on other sites More sharing options...
Nine Posted May 18, 2021 Share Posted May 18, 2021 (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 May 18, 2021 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
JockoDundee Posted May 18, 2021 Share Posted May 18, 2021 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 _ArrayAdd($WichInputs,$Input4) ElseIf GUICtrlRead($Input4) <> $Value4 Then $SomethingChanged = True _ArrayAdd($WichInputs,$Input4) Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now