youtuber Posted May 19, 2019 Share Posted May 19, 2019 I want to get extensions from checkbox names #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 195, 125) $Button1 = GUICtrlCreateButton("ok", 86, 64, 75, 34) Dim $Checkbox[3] $Checkbox[0] = GUICtrlCreateCheckbox(".JPG", 14, 32, 49, 17) $Checkbox[1] = GUICtrlCreateCheckbox(".PNG", 68, 32, 49, 17) $Checkbox[2] = GUICtrlCreateCheckbox(".GIF", 127, 32, 49, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 For $i = 0 To UBound($Checkbox) - 1 If GUICtrlRead($Checkbox[$i]) = $GUI_CHECKED Then ConsoleWrite($Checkbox[$i] & @CRLF) Next EndSwitch WEnd Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted May 19, 2019 Share Posted May 19, 2019 (edited) @youtuber Create a two-dimension array; in the first column, you store the ControlID of the checkbox, and in the second column you store its label, so when you use GUICtrlRead() in a For...Next loop, you just need to use For $i = 0 To UBound($arrCheckBoxes) - 1 Step 1 If GUICtrlRead($arrCheckBoxes[$i][0]) = $GUI_CHECKED Then ConsoleWrite($arrCheckBoxes[$i][1] & @CRLF) Next to retrieve the information about the label of the checked checkbox(es) Edited May 19, 2019 by FrancescoDiMuro youtuber 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
mikell Posted May 19, 2019 Share Posted May 19, 2019 For $i = 0 To UBound($Checkbox) - 1 If GUICtrlRead($Checkbox[$i]) = $GUI_CHECKED Then ConsoleWrite(GUICtrlRead($Checkbox[$i], 1) & @CRLF) Next Exit, youtuber and FrancescoDiMuro 3 Link to comment Share on other sites More sharing options...
youtuber Posted May 19, 2019 Author Share Posted May 19, 2019 (edited) @mikell Thanks very good @FrancescoDiMuro Did you mean a two dimension array like this? #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 195, 125) $Button1 = GUICtrlCreateButton("ok", 86, 64, 75, 34) Dim $Checkbox[3][2] $Checkbox[0][".jpg"] = GUICtrlCreateCheckbox(".JPG", 14, 32, 49, 17) $Checkbox[1][".png"] = GUICtrlCreateCheckbox(".PNG", 68, 32, 49, 17) $Checkbox[2][".gif"] = GUICtrlCreateCheckbox(".GIF", 127, 32, 49, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 For $i = 0 To UBound($Checkbox) - 1 Step 1 If GUICtrlRead($Checkbox[$i][0]) = $GUI_CHECKED Then ConsoleWrite($Checkbox[$i][1] & @CRLF) Next EndSwitch WEnd Edited May 19, 2019 by youtuber Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted May 19, 2019 Share Posted May 19, 2019 (edited) @youtuber Something like this: $arrCheckBoxes[0][0] = GUICtrlCreateCheckbox(...) $arrCheckboxes[0][1] = ".JPG" ; And so on for as many checkboxes you want to set By the way, @mikell gives you the easiest solution, as long as the text you display is the one you want to retrieve; else, you need to do something like above Edited May 19, 2019 by FrancescoDiMuro youtuber 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
youtuber Posted May 19, 2019 Author Share Posted May 19, 2019 @FrancescoDiMuro I still don't understand what you mean, so I'm really sorry, is it? Dim $Checkbox[3][2] $Checkbox[0][0] = GUICtrlCreateCheckbox(".JPG", 14, 32, 49, 17) $Checkbox[0][1] = GUICtrlCreateCheckbox(".PNG", 68, 32, 49, 17) $Checkbox[0][2] = GUICtrlCreateCheckbox(".GIF", 127, 32, 49, 17) Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted May 20, 2019 Share Posted May 20, 2019 (edited) @youtuber Take the array as a table, in which the first dimension is the row index, and the second dimension is the column index. In the first column, you store the ControlID of the checkbox, so, you do something like this: ; Global array with three rows and two columns Global $arrCheckBoxes[3][2] ; Store the ControlID of the CheckBox in the first row and first column of the array $arrCheckBoxes[0][0] = GUICtrlCreateCheckBox(...) ; Store the additional information in the first row and the second column of the array $arrCheckBoxes[0][1] = ".JPG" ; Go on as many rows you have (three in this case) If you want to know more about arrays, you can find a Wiki here and a more in-depth thread here. By the way, feel free to ask if you need any help Edited May 20, 2019 by FrancescoDiMuro youtuber 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
youtuber Posted May 21, 2019 Author Share Posted May 21, 2019 @FrancescoDiMuro I still can't figure it out anyway I don't really understand :( not happening Global $Checkbox[3][2] ; Store the ControlID of the CheckBox in the first row and first column of the array $Checkbox[0][0] = GUICtrlCreateCheckBox(".JPG", 14, 32, 49, 17) $Checkbox[0][0] = GUICtrlCreateCheckBox(".PNG", 68, 32, 49, 17) $Checkbox[0][0] = GUICtrlCreateCheckBox(".GIF", 127, 32, 49, 17) ; Store the additional information in the first row and the second column of the array $Checkbox[0][1] = ".JPG" $Checkbox[0][2] = ".PNG" $Checkbox[0][3] = ".GIF" or Global $Checkbox[3][2] ; Store the ControlID of the CheckBox in the first row and first column of the array $Checkbox[0][0] = GUICtrlCreateCheckBox(".JPG", 14, 32, 49, 17) $Checkbox[0][0] = GUICtrlCreateCheckBox(".PNG", 68, 32, 49, 17) $Checkbox[0][0] = GUICtrlCreateCheckBox(".GIF", 127, 32, 49, 17) ; Store the additional information in the first row and the second column of the array $Checkbox[0][1] = [".JPG", ".PNG", ".GIF"] or Global $Checkbox[3][2] ; Store the ControlID of the CheckBox in the first row and first column of the array $Checkbox[0][0] = GUICtrlCreateCheckBox(".JPG", 14, 32, 49, 17) & GUICtrlCreateCheckBox(".PNG", 68, 32, 49, 17) & GUICtrlCreateCheckBox(".GIF", 127, 32, 49, 17) ; Store the additional information in the first row and the second column of the array $CheckBox[0][1] = ["JPG", "PNG", "GIF"] Link to comment Share on other sites More sharing options...
spudw2k Posted May 21, 2019 Share Posted May 21, 2019 (edited) Like a so Global $Checkbox[3][2] ; Store the ControlID of the CheckBox in the first row and first column of the array $Checkbox[0][0] = GUICtrlCreateCheckBox(".JPG", 14, 32, 49, 17) $Checkbox[1][0] = GUICtrlCreateCheckBox(".PNG", 68, 32, 49, 17) $Checkbox[2][0] = GUICtrlCreateCheckBox(".GIF", 127, 32, 49, 17) ; Store the additional information in the first row and the second column of the array $Checkbox[0][1] = ".JPG" $Checkbox[1][1] = ".PNG" $Checkbox[2][1] = ".GIF" Maybe this will be helpful visualize aid to understand how the array indexes are used. Const $iCheckboxCount = 3, $iCheckboxArrayParams = 2 ;Define How Many Checkboxes and How Many "Parameters" about the Checkbox to store Enum $iCheckboxParamCtrlID, $iCheckboxParamText ;Define the Array Indexes for the Checkbox "Parameters" (Checkbox Ctrl IDs and Checkbox Text values) Enum $iCheckbox1, $iCheckbox2, $iCheckbox3 ;Define The Checkbox Instances Global $Checkbox[$iCheckboxCount][$iCheckboxArrayParams] ;Build Array for storing Checkboxes and "Parameters" $Checkbox[$iCheckbox1][$iCheckboxParamCtrlID] = GUICtrlCreateCheckBox(".JPG", 14, 32, 49, 17) $Checkbox[$iCheckbox2][$iCheckboxParamCtrlID] = GUICtrlCreateCheckBox(".PNG", 68, 32, 49, 17) $Checkbox[$iCheckbox3][$iCheckboxParamCtrlID] = GUICtrlCreateCheckBox(".GIF", 127, 32, 49, 17) $Checkbox[$iCheckbox1][$iCheckboxParamText] = ".JPG" $Checkbox[$iCheckbox2][$iCheckboxParamText] = ".PNG" $Checkbox[$iCheckbox3][$iCheckboxParamText] = ".GIF" I'm not saying this is how it should be done; it's just to help illustrate. Nothing wrong with doing it this way though (using enums to make meaningful/readable names for array index values). I will say that declaring each checkbox index (i.e. $iCheckbox1, $iCheckbox2, etc.) is overkill, especially if the Array name is already meaningful to denote what is contained in the array. Having said all of that, I still don't particularly see the value or need to store the text when it can easily be retrieved on demand--with negligible performance impact--using the GUICtrlRead function @mikell laid out above. Edited May 21, 2019 by spudw2k youtuber 1 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...
Rex Posted May 21, 2019 Share Posted May 21, 2019 Or use the extended GuiCtrlRead #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 195, 125) $Button1 = GUICtrlCreateButton("ok", 86, 64, 75, 34) Dim $Checkbox[3] $Checkbox[0] = GUICtrlCreateCheckbox(".JPG", 14, 32, 49, 17) $Checkbox[1] = GUICtrlCreateCheckbox(".PNG", 68, 32, 49, 17) $Checkbox[2] = GUICtrlCreateCheckbox(".GIF", 127, 32, 49, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 For $i = 0 To UBound($Checkbox) - 1 If GUICtrlRead($Checkbox[$i]) = $GUI_CHECKED Then ConsoleWrite(GuiCtrlRead($Checkbox[$i], $GUI_READ_EXTENDED) & @CRLF) Next EndSwitch WEnd youtuber 1 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted May 21, 2019 Share Posted May 21, 2019 (edited) @youtuber You've been suggested to read a tutorial about arrays, because, even with a sample, you misundertood the difference between rows and columns in your first script, then treat a two-dimension array like a one-dimension array when assigning text in the first column in your second script, and finally treat the two-dimension like a one-dimension array, both for the checkboxes creation and texts assignment. I suggest you once again to read carefully the array tutorials, and to try with simpler examples to get into them. @spudw2k @Rex The whole speech was about letting the user experiment another (possibly) useful way to do what he was trying to do. He was already pointed out to a solution (the @mikell one), and so if he was keep trying the other solution, or he didn't tried the @mikell script, or he it isn't what he was needing. Edited May 21, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
spudw2k Posted May 21, 2019 Share Posted May 21, 2019 (edited) 1 hour ago, FrancescoDiMuro said: The whole speech was about letting the user experiment another (possibly) useful way to do what he was trying to do. Understood. It looked like he was trying, but wasn't quite there. After seeing some effort on his part I didn't think it was unreasonable to show where he was incorrect and perhaps shed light in a different way to help him understand 1 hour ago, FrancescoDiMuro said: He was already pointed out to a solution (the @mikell one) Agreed, but sometimes I have even been guilty of missing help someone gave me in the past and it took another member to point that out to me. I want to commend @Rex though for not using a magic number in his example. Edited May 21, 2019 by spudw2k 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...
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