amin84 Posted September 19, 2010 Share Posted September 19, 2010 Hello, I'm writing a small dynamic GUI which will list the files inside a folder called 'apps' at the script location. For every file in that folder, the GUI will make a check box with the name of that file. Now the problem is that I want to generate a list of checked boxes to do some tasks but as soon as I press the button, it will give me numbers! Any help is greatly appreciated. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> $folderToList = 'apps/' $vSpacer = 24 $hSpacer = 16 $tasks = '' $noFilesFound = '' $appList = _FileListToArray($folderToList, "*", 1) If @error = 1 Then Exit EndIf If $appList = '' Then $noFilesFound = 'No files found inside "apps\" folder.' EndIf ;~ _ArrayDisplay($appList) $autoAppLister = GUICreate("Auto App Lister", 370, 370, 192, 124) $appListGrp = GUICtrlCreateGroup("App List", 8, 8, 353, 313) If $noFilesFound <> '' Then $noFilesLbl = GUICtrlCreateLabel($noFilesFound, 16, 152, 318, 28, $SS_CENTER) GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif") Else If $appList <> '' Then For $i = 1 To $appList[0] $appList[$i] = GUICtrlCreateCheckbox($appList[$i], $hSpacer, $vSpacer, 161, 17) $vSpacer += 16 If $vSpacer > 300 Then $vSpacer = 24 $hSpacer = 192 EndIf Next EndIf EndIf GUICtrlCreateGroup("", -99, -99, 1, 1) If $appList <> '' Then $installBtn = GUICtrlCreateButton("Show List Of Checked Boxes", 8, 328, 353, 33, $WS_GROUP) Else $installBtn = GUICtrlCreateButton("Show List Of Checked Boxes", 8, 328, 353, 33, $WS_GROUP) GUICtrlSetState(-1, $GUI_DISABLE) EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $installBtn _listCheck() EndSwitch WEnd Func _listCheck() For $i = 1 To $appList[0] If GUICtrlRead($appList[$i]) = 1 Then $tasks &= $appList[$i] & @LF EndIf Next $okPressed = MsgBox(0,'',$tasks) If $okPressed = 1 Then $tasks = '' EndIf EndFunc ;==>_listCheck Link to comment Share on other sites More sharing options...
smashly Posted September 19, 2010 Share Posted September 19, 2010 Hi, the numbers that are returned are Control ID's of the selected checkboxes, use GUICtrlRead($appList[$i], 1) to get the text of the checkbox.eg:expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> $folderToList = @ScriptDir & '\apps\' $vSpacer = 24 $hSpacer = 16 $tasks = '' $noFilesFound = '' $appList = _FileListToArray($folderToList, "*", 1) If @error = 1 Then Exit EndIf If $appList = '' Then $noFilesFound = 'No files found inside "apps\" folder.' EndIf ;~ _ArrayDisplay($appList) $autoAppLister = GUICreate("Auto App Lister", 370, 370, 192, 124) $appListGrp = GUICtrlCreateGroup("App List", 8, 8, 353, 313) If $noFilesFound <> '' Then $noFilesLbl = GUICtrlCreateLabel($noFilesFound, 16, 152, 318, 28, $SS_CENTER) GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif") Else If $appList <> '' Then For $i = 1 To $appList[0] $appList[$i] = GUICtrlCreateCheckbox($appList[$i], $hSpacer, $vSpacer, 161, 17) $vSpacer += 16 If $vSpacer > 300 Then $vSpacer = 24 $hSpacer = 192 EndIf Next EndIf EndIf GUICtrlCreateGroup("", -99, -99, 1, 1) If $appList <> '' Then $installBtn = GUICtrlCreateButton("Show List Of Checked Boxes", 8, 328, 353, 33, $WS_GROUP) Else $installBtn = GUICtrlCreateButton("Show List Of Checked Boxes", 8, 328, 353, 33, $WS_GROUP) GUICtrlSetState(-1, $GUI_DISABLE) EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $installBtn _listCheck() EndSwitch WEnd Func _listCheck() For $i = 1 To $appList[0] If GUICtrlRead($appList[$i]) = 1 Then $tasks &= $folderToList & GUICtrlRead($appList[$i], 1) & @LF EndIf Next $okPressed = MsgBox(0,'Files Selected', $tasks) If $okPressed = 1 Then $tasks = '' EndIf EndFunc ;==>_listCheckCheers Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2010 Moderators Share Posted September 19, 2010 leomoon, You were overwriting your list of files when you created the checkboxes. So when you tried to read the name of the file, you got the ControlID instead. This shows how to do it: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> $folderToList = @ScriptDir $vSpacer = 24 $hSpacer = 16 $tasks = '' $noFilesFound = '' Global $chkList[100] $appList = _FileListToArray($folderToList, "*", 1) If @error = 1 Then Exit EndIf Global $chkList[$appList[0] + 1] ; Declare an array to hold the checkbox ControlIDs If $appList = '' Then $noFilesFound = 'No files found inside "apps\" folder.' EndIf ;~ _ArrayDisplay($appList) $autoAppLister = GUICreate("Auto App Lister", 370, 370, 192, 124) $appListGrp = GUICtrlCreateGroup("App List", 8, 8, 353, 313) If $noFilesFound <> '' Then $noFilesLbl = GUICtrlCreateLabel($noFilesFound, 16, 152, 318, 28, $SS_CENTER) GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif") Else If $appList <> '' Then For $i = 1 To $appList[0] $chkList[$i] = GUICtrlCreateCheckbox($appList[$i], $hSpacer, $vSpacer, 161, 17) ; Save the ControlIds on the new array $vSpacer += 16 If $vSpacer > 300 Then $vSpacer = 24 $hSpacer = 192 EndIf Next EndIf EndIf GUICtrlCreateGroup("", -99, -99, 1, 1) $installBtn = GUICtrlCreateButton("Show List Of Checked Boxes", 8, 328, 353, 33, $WS_GROUP) If $appList = '' Then GUICtrlSetState(-1, $GUI_DISABLE) ; Is it not more elegant? GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $installBtn _listCheck() EndSwitch WEnd Func _listCheck() For $i = 1 To $appList[0] If GUICtrlRead($chkList[$i]) = 1 Then ; Check the checkboxes $tasks &= $appList[$i] & @LF ; Add the text from the file list EndIf Next $okPressed = MsgBox(0, '', $tasks) If $okPressed = 1 Then $tasks = '' EndIf EndFunc ;==>_listCheck Note also the rather more elegant syntax for disabling your button. Please ask if you have any questions. 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...
amin84 Posted September 19, 2010 Author Share Posted September 19, 2010 (edited) AWESOME! I learn new stuff here EVERY DAY! The new way of disabling button is definitely MORE elegant and a lot easier to read. I'm using smashly's script with the elegant way of disabling the button by Melba23 because Melba23's script will give error if there are no files in the directory @ line # 20 where it says: "Global $chkList[$appList[0] + 1] ; Declare an array to hold the checkbox ControlIDs". Thanks a lot. Here is the final script for anyone who want a dynamic GUI sample: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> $folderToList = @ScriptDir & '\apps\' $vSpacer = 24 $hSpacer = 16 $tasks = '' $noFilesFound = '' $appList = _FileListToArray($folderToList, "*", 1) If @error = 1 Then Exit EndIf If $appList = '' Then $noFilesFound = 'No files found inside "apps\" folder.' EndIf ;~ _ArrayDisplay($appList) $autoAppLister = GUICreate("Auto App Lister", 370, 370) $appListGrp = GUICtrlCreateGroup("App List", 8, 8, 353, 313) If $noFilesFound <> '' Then $noFilesLbl = GUICtrlCreateLabel($noFilesFound, 16, 152, 318, 28, $SS_CENTER) GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif") Else If $appList <> '' Then For $i = 1 To $appList[0] $appList[$i] = GUICtrlCreateCheckbox($appList[$i], $hSpacer, $vSpacer, 161, 17) $vSpacer += 16 If $vSpacer > 300 Then $vSpacer = 24 $hSpacer = 192 EndIf Next EndIf EndIf GUICtrlCreateGroup("", -99, -99, 1, 1) $installBtn = GUICtrlCreateButton("Show The List Of Selected Check Boxes", 8, 328, 353, 33, $WS_GROUP) If $appList = '' Then GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $installBtn _listCheck() EndSwitch WEnd Func _listCheck() For $i = 1 To $appList[0] If GUICtrlRead($appList[$i]) = 1 Then $tasks &= $folderToList & GUICtrlRead($appList[$i], 1) & @LF EndIf Next If $tasks <> '' Then $okPressed = MsgBox(0,'Files Selected', $tasks) Else $okPressed = MsgBox(0,'Oops!','Nothing selected!') EndIf If $okPressed = 1 Then $tasks = '' EndIf EndFunc ;==>_listCheck Edited September 19, 2010 by leomoon 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