Ghost1982 Posted April 6, 2021 Share Posted April 6, 2021 (edited) Hello I''m preparing a GUI with checkboxes pointing to websites (for now just fake addresses for test). From declared array I'm creating GUI with checkboxes names. as you can see i'm using a loop for that. However my loop in Select All button doesn't work. I'm also using same type of loop just like in GUI creation but Select all only selects the last value. Case $ButtonSel. Why? Global $Chrome = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" Local $Arr[3] = ["Movies", "Games", "Books"] Global $Max = UBound($Arr) - 1 GUICreate("INTERNET SITES", 500, 200, -1, -1) $Top = 10 For $i = 0 To $Max Global $Chkbx = GUICtrlCreateCheckbox($Arr[$i], 10, $Top, 150, 20) $Top += 30 Next $ButtonSel = GUICtrlCreateButton("Select All", 10, 110, 150, 20) $ButtonOpen = GUICtrlCreateButton("Open", 10, 140, 150, 20) GUISetState(@SW_SHOW) Local $ChkbxSel = 0 While 1 $ChkbxSel = GUIGetMsg() Switch $ChkbxSel Case $GUI_EVENT_CLOSE ExitLoop Case $ButtonSel For $i = 0 To $Max GUICtrlSetState($Chkbx, $GUI_CHECKED) Next Case $ButtonOpen $Srv = GUICtrlRead($ChkbxSel) $Addr = " https://www." & $Srv & ".com" ;MsgBox($MB_OK,"",$Addr & " selected") Run($Chrome & $Addr) EndSwitch WEnd Edited April 6, 2021 by Ghost1982 Link to comment Share on other sites More sharing options...
Danp2 Posted April 6, 2021 Share Posted April 6, 2021 You likely need to save the value returned from GUICtrlCreateCheckbox to an array instead of a regular variable. Then you could use this value in your GUICtrlSetState. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted April 6, 2021 Share Posted April 6, 2021 Never declare Global or Local in a loop as this may override the previous assignment. Always declare variables outside any embedded statement (While, Do, If, etc.) Danp2 1 “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...
spudw2k Posted April 7, 2021 Share Posted April 7, 2021 Here is a snippet related to what you are working on. It might give you some ideas. It uses an array to track the controls as Danp2 suggested, but also uses a TreeView control instead which simplifies placement of the CheckBoxes. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
JockoDundee Posted April 7, 2021 Share Posted April 7, 2021 10 hours ago, Nine said: Never declare Global or Local in a loop as this may override the previous assignment. I agree we shouldn’t, but what way in a practical sense is For $i = 0 To $Max Global $Chkbx = GUICtrlCreateCheckbox($Arr[$i], 10, $Top, 150, 20) $Top += 30 Next different than For $i = 0 To $Max $Chkbx = GUICtrlCreateCheckbox($Arr[$i], 10, $Top, 150, 20) $Top += 30 Next and wouldn’t any “override [of] the previous assignment” occur regardless of whether the code is looped or not? Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Ghost1982 Posted April 7, 2021 Author Share Posted April 7, 2021 (edited) 8 hours ago, spudw2k said: Here is a snippet related to what you are working on. It might give you some ideas. It uses an array to track the controls as Danp2 suggested, but also uses a TreeView control instead which simplifies placement of the CheckBoxes. Looks great, Why are you using 0 + 1? Dim $SelectionArray[$ChoiceArray[0] + 1] For now I've done something like below, The simples as it can be. Also I've added Unselect All button. expandcollapse popupGlobal $Chrome = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" $Arr = StringSplit("Movies|Games|Books|Sport|News","|") Dim $Sel[$Arr[0] + 1] GUICreate("IBM DataPower Gateway", 500, 400, -1, -1) $Top = 10 For $i = 1 To $Arr[0] $Sel[$i] = GUICtrlCreateCheckbox($Arr[$i], 10, $Top, 150, 20) $Top += 25 Next $ButtonSel = GUICtrlCreateButton("Select All", 10, 150, 150, 20) $ButtonUnSel = GUICtrlCreateButton("Unselect All", 10, 180, 150, 20) $ButtonOpen = GUICtrlCreateButton("Open", 10, 210, 150, 20) GUISetState(@SW_SHOW) While 1 $ChkbxSel = GUIGetMsg() Switch $ChkbxSel Case $GUI_EVENT_CLOSE ExitLoop Case $ButtonSel For $i = 1 To $Arr[0] GUICtrlSetState($Sel[$i], $GUI_CHECKED) Next Case $ButtonUnSel For $i = 1 To $Arr[0] GUICtrlSetState($Sel[$i], $GUI_UNCHECKED) Next Case $ButtonOpen For $i = 1 To $Arr[0] If GUICtrlRead($Sel[$i]) = $GUI_CHECKED Then $Addr = " https://www." & $Arr[$i] & ".com" ;MsgBox($MB_OK,"",$Addr & " selected") Run($Chrome & $Addr) ;MsgBox($MB_OK,"",$Arr[$i] & " selected") EndIf Next EndSwitch WEnd However now I'm thinkg about another problem. The more items I'm adding into array the higher the interface grows. Is there any command that allows to quickly split checkboxes into columns? i.e. 3 columns with max 3 items. Edited April 7, 2021 by Ghost1982 Link to comment Share on other sites More sharing options...
Zedna Posted April 7, 2021 Share Posted April 7, 2021 Use function Mod() - modulus operation Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Ghost1982 Posted April 8, 2021 Author Share Posted April 8, 2021 17 hours ago, Zedna said: Use function Mod() - modulus operation Isn't it diving by two? Only thing that comes to my mind is to create a some kind of loop where I'll define number of columns and rows. However I'm not sure how should I point in the loop when the row limit (3) is reached. Link to comment Share on other sites More sharing options...
Zedna Posted April 8, 2021 Share Posted April 8, 2021 expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global $Chrome = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" $Arr = StringSplit("Movies|Games|Books|Sport|News|Movies2|Games2|Books2|Sport2|News2|Movies3|Games3|Books3|Sport3","|") Dim $Sel[$Arr[0] + 1] GUICreate("IBM DataPower Gateway", 500, 400, -1, -1) $Left = 10 $Top = 10 $rows = 5 ; number of checkboxes in each column $TopMax = $Top + $rows*25 For $i = 1 To $Arr[0] $Sel[$i] = GUICtrlCreateCheckbox($Arr[$i], $Left, $Top, 150, 20) If Mod($i, $rows) = 0 Then $Left += 150 $Top = 10 Else $Top += 25 EndIf Next $ButtonSel = GUICtrlCreateButton("Select All", 10, $TopMax, 150, 20) $ButtonUnSel = GUICtrlCreateButton("Unselect All", 10, $TopMax + 30, 150, 20) $ButtonOpen = GUICtrlCreateButton("Open", 10, $TopMax + 60, 150, 20) GUISetState(@SW_SHOW) While 1 $ChkbxSel = GUIGetMsg() Switch $ChkbxSel Case $GUI_EVENT_CLOSE ExitLoop Case $ButtonSel For $i = 1 To $Arr[0] GUICtrlSetState($Sel[$i], $GUI_CHECKED) Next Case $ButtonUnSel For $i = 1 To $Arr[0] GUICtrlSetState($Sel[$i], $GUI_UNCHECKED) Next Case $ButtonOpen For $i = 1 To $Arr[0] If GUICtrlRead($Sel[$i]) = $GUI_CHECKED Then $Addr = " https://www." & $Arr[$i] & ".com" ;MsgBox($MB_OK,"",$Addr & " selected") Run($Chrome & $Addr) ;MsgBox($MB_OK,"",$Arr[$i] & " selected") EndIf Next EndSwitch WEnd spudw2k 1 Resources UDF ResourcesEx UDF AutoIt Forum Search 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