Auto42 Posted June 9, 2014 Share Posted June 9, 2014 Hi, first of all I am glad that the AutoIt language exists, as it enables me to create an GUI user interface with ease. Furthermore I am pleased about this forum with many good and helpful code snippets and the AutoIt documentation itselfs. I have not really much experience in programming but I 'd like to discuss some points that are in my opinion curious: 1) The function _FileListToArray returns an Integer of type Int32 if no matching file of the given filetyp (e.g. *.pdf) was found (precisely it returns "0"). In every other case an array is returned. I can't rely on the type that is returned thats why I have to build in a check if type "_isarray" or something like this. 2) The _ArrayMin() function returns nothing, if no values were given. This makes the function completely pointless in my opinion. Example to check the state of three checkboxes, where multiple checkboxes can be checked by the user: If Bool($Checkbox_1) Or Bool($Checkbox_2) Or Bool ($Checkbox_3) Then Dim $start[3][2] If Bool($Checkbox_1) Then $start[0][0] = 1 $start[0][1] = 1 EndIf If Bool($Checkbox_2) Then $start[1][0] = 2 $start[1][1] = 2 EndIf If Bool ($Checkbox_3) Then $start[2][0] = 3 $start[2][1] = 3 EndIf $start_exp = "[" & _ArrayMin($start, 1, 0, 0, 0) & "-" & _ArrayMax($start, 1, 0, 0, 1) & "]" Else MsgBox(48, "Error", "No mandator is choosen! Please select at least one mandator.") EndIf Func Bool(Const ByRef $checkbox) If GUICtrlRead($checkbox) = $GUI_CHECKED Then Return 1 ElseIf GUICtrlRead($checkbox) = $GUI_UNCHECKED Then Return 0 EndIf EndFunc This code returns something like [-3] or [-2] for the term $start_exp. If I fill the array with values first e.g. Dim $start = [[0, 0], [0, 0], [0, 0]] the result will always be 0 because 0 is the min value whatever checkbox the user has been clicked. In both cases the _ArrayMin() Function does not do what I (would) like it to do . Obviously that already was noted by Dirgi in this >thread. Unfortunately his function does not support the $iSubItem (column to search) parameter. In case you have a better idea: I check the state of the boxes not in "real-time" (= not just after it has been clicked). Checkbox state check and value assignment is done after another button has been clicked. Regards Auto42 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 9, 2014 Moderators Share Posted June 9, 2014 Auto42,You have do some form of test to check if you have a valid return to errorcheck your code. If no files are found then _FileListToArray sets the @error to a specified value - I suggest that is a better test for success than testing for an array. As for your second point, I have absolutely no idea what you are trying to do with that array - can you explain its purpose and why you are looking for the min and max values within it? We might then be able to suggest a better solution. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrewManNH Posted June 9, 2014 Share Posted June 9, 2014 I'm not sure what you'd want _FIleListToArray to return if it doesn't find the file(s), check @error to see if it's <> 0. You should ALWAYS check to see if the function works after calling it. _ArrayMin is doing exactly what you tell it to do, look for the lowest value in an array, if it's zero, it's going to return zero. To check a checkbox, loop through the array of control IDs and see if they're checked. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Auto42 Posted June 9, 2014 Author Share Posted June 9, 2014 Hi M23, wow that was quite fast. For the frist point: Okay I got it and will check for errors. Besides that it would be nice to return an empty array if no files were found, instead of an integer. Second point: I have three different clients A, B, C. The output $start_exp will be part of an Regular Expression of type StringRegexp(..., ([1-3]d{6}(?=s))) The user can choose any mandators (at least one, two or all three). Base on his choice the frist number of the term [n1 - n2] is 1 if A is choosen 2 if B is choosen 3 if C is choosen the second number n2 is 1 if A is choosen 2 if B is choosen 3 if C is choosen The complete term defines a 7 digit number that is ranged from 1000000 to 3999999. I lookup pdf files to find this pattern. Unfortunately the pdf files may include other 7 digit numbers. Thats why I want to diminish the range I am looking for as good as possible. If the user just check the boxes A and B I will just search for 1000000 - 2999999 or for the boxes B and C I will just filter numbers from 2000000 - 3999999. Regards Auto42 Link to comment Share on other sites More sharing options...
BrewManNH Posted June 9, 2014 Share Posted June 9, 2014 Does the variables $Checkbox_# contain the control IDs of the checkboxes? If so, you need to use GUICtrlRead($Checkbox_1) to read the checkbox to see if it's checked or not, you can't just use the control ID, because that never changes. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 9, 2014 Moderators Share Posted June 9, 2014 Auto42,We will have disagree about returning an array if no files are found. As to your second question, I would get the SRE term like this:#include <GUIConstantsEx.au3> Global $aCheck[3] $hGUI = GUICreate("Test", 500, 500) For $i = 0 To 2 $aCheck[$i] = GUICtrlCreateCheckbox("Check " & $i + 1, 10, 10 + ($i * 30), 200, 20) Next $cGo = GUICtrlCreateButton("Go!", 10, 100, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cGo $iMin = 0 $iMax = 0 For $i = 0 To 2 If GUICtrlRead($aCheck[$i]) = 1 Then If Not $iMin Then $iMin = $i + 1 EndIf If GUICtrlRead($aCheck[2 - $i]) = 1 Then If Not $iMax Then $iMax = 2 - $i + 1 EndIf Next $start_exp = "[" & $iMin & "-" & $iMax & "]" ConsoleWrite($start_exp & @CRLF) EndSwitch WEndPlease ask if you have any questions about the code. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Auto42 Posted June 9, 2014 Author Share Posted June 9, 2014 Hi BrewManNH, thanks for your advice first. As implemented in the Bool function, thats exactly the way I am checking my boxes and the Bool function returns 1 or 0 reflecting the box is checked or not. This does work like it should work. My Checkboxes are defined as: $Checkbox_1 = GUICtrlCreateCheckbox("A", 400, 30, 70, 20) $Checkbox_2 = GUICtrlCreateCheckbox("B", 400, 50, 70, 20) $Checkbox_3 = GUICtrlCreateCheckbox("C", 400, 70, 70, 20) I dont like to use a switch ... case construct where I have to discribe all seven (?) cases to eval all different box-check-situations: Case box 1 ... Case box 2... Case box 3... Case box 1 AND 2 Case box 2 AND 3 Case box 1 AND 3 (in my case same result as 1 AND 2 AND 3) Case no box check (--> Raise msg box error) I thought there would exist a more "advanced" possibility to implement this. Regards Auto42 Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted June 9, 2014 Moderators Solution Share Posted June 9, 2014 Auto42, I dont like to use a switch ... case construct where I have to discribe all seven (?) casesAnd with the algorithm I used you do not have to - as you can see when I expand it to have 7 checkboxes: expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global $aCheck[7] $hGUI = GUICreate("Test", 500, 500) $iBound = UBound($aCheck) - 1 For $i = 0 To $iBound $aCheck[$i] = GUICtrlCreateCheckbox("Check " & $i + 1, 10, 10 + ($i * 30), 200, 20) Next $cGo = GUICtrlCreateButton("Go!", 10, 460, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cGo $iMin = 0 $iMax = 0 For $i = 0 To $iBound If GUICtrlRead($aCheck[$i]) = 1 Then If Not $iMin Then $iMin = $i + 1 EndIf If GUICtrlRead($aCheck[$iBound - $i]) = 1 Then If Not $iMax Then $iMax = $iBound - $i + 1 EndIf Next If $iMin And $iMax Then $start_exp = "[" & $iMin & "-" & $iMax & "]" MsgBox($MB_SYSTEMMODAL, "Result", $start_exp) Else MsgBox($MB_SYSTEMMODAL, "Error", "No mandator is choosen! Please select at least one mandator.") EndIf EndSwitch WEndYou check the boxes in both ascending and descending order and set the $iMin & $imax variables to the first checked box you find in each direction - if no boxes are checked then neither variable is set and you get an error signalled. Clearer now? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrewManNH Posted June 9, 2014 Share Posted June 9, 2014 Sorry, I missed that, probably didn't scroll far enough down. BTW, your Bool function could be shortened considerably. Func Bool(Const ByRef $checkbox) Return (GUICtrlRead($checkbox) = $GUI_CHECKED) EndFunc It can only be in one or the other state (unless you use the 3 state checkbox style), so it returns true or false. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Auto42 Posted June 9, 2014 Author Share Posted June 9, 2014 Thanks guys all together. I will try your proposal tomorrow M23 but I think it will solve my problem :-). I probably never would have thought of that on my own. Gn8 Auto42 Link to comment Share on other sites More sharing options...
Auto42 Posted June 10, 2014 Author Share Posted June 10, 2014 The proposed code works fine for me . I put it in an extra function to keep the main-loop "clean & clear". *happy* And @ BrewManNH: That was a term I was looking for too. I tested what GUICtrlRead($checkbox) returned and was confused that it returns 1 if the box is checked and 4 if the box is not checked. I expected a standard boolean return and obviously failed to build up that obvious solution you presented. Auto42 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 10, 2014 Moderators Share Posted June 10, 2014 Auto42,Delighted we solved your problem. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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