timdecker Posted March 30, 2015 Posted March 30, 2015 I would like to have the bottons only enabled if the checkboxes are checked. Below is the code I am using, the comments between the #CS and #CE is what I was trying to get to work... expandcollapse popup#include <file.au3> #include <GUICONSTANTS.au3> Global $a_csv $s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)") If @error Then MsgBox(4096, "", "No File(s) chosen") Exit Else _FileReadToArray($s_Path, $a_csv) GUICreate("CSV Listview", 900, 450, -1, -1) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 600, 210) $checkboxName = StringSplit($a_csv[1], ",") $iCount = $checkboxName[0] Global $aCheck[$iCount + 1] Global $mapColumn[$iCount + 1] $nextSample = GUICtrlCreateButton("Map sample submition button ", 395, 320, 180, 30) $runProg = GUICtrlCreateButton("Run Program", 700, 400, 180, 30) $button_enabled = 1 For $j = 1 To $iCount ; Store controIDs of the checkboxes $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30) $mapColumn[$j] = GUICtrlCreateButton("Map " & '"' & $checkboxName[$j] & '"' & " to input box", 150, 190 + (50 * $j), 180, 30) GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED) GUICtrlSetState($mapColumn[$j], $GUI_DISABLE) Next #cs While 1 if BitAnd(GUICtrlRead($aCheck[$j]),$GUI_UNCHECKED) = $GUI_UNCHECKED Then GUICtrlSetState($mapColumn[$j], $GUI_DISABLE) $button_enabled = 0 ElseIf $button_enabled = 0 And BitAnd(GUICtrlRead($aCheck[$j]),$GUI_UNCHECKED) = $GUI_CHECKED Then GUICtrlSetState($mapColumn[$j], $GUI_ENABLE) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : GUICtrlSetState($mapColumn[$j], $GUI_ENABLE) = ' & GUICtrlSetState($mapColumn[$j], $GUI_ENABLE) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $button_enabled = 1 EndIf wend #ce GUISetState() For $i = 2 To UBound($a_csv) - 1 $s_temp = StringReplace($a_csv[$i], ",", "|") GUICtrlCreateListViewItem($s_temp, $listview) Next EndIf While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Exit
ahmet Posted March 30, 2015 Posted March 30, 2015 Do you want something like this below? #include <GUIConstantsEx.au3> Global $iNumOfCtrls=5 Global $aChkBox[$iNumOfCtrls], $aBtn[$iNumOfCtrls] $hMain=GUICreate("test") For $i=0 To $iNumOfCtrls-1 $aChkBox[$i]=GUICtrlCreateCheckbox("CheckBox " & $i,10,10+$i*22,200,22) $aBtn[$i]=GUICtrlCreateButton("Button " & $i,10+200+40,10+$i*22,200,22) GUICtrlSetState(-1,$GUI_DISABLE) Next GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch For $i=0 To $iNumOfCtrls-1 If BitAND(GUICtrlGetState($aBtn[$i]),$GUI_DISABLE) And BitAND(GUICtrlRead($aChkBox[$i]),$GUI_CHECKED) Then GUICtrlSetState($aBtn[$i],$GUI_ENABLE) ExitLoop ElseIf BitAND(GUICtrlGetState($aBtn[$i]),$GUI_ENABLE) And BitAND(GUICtrlRead($aChkBox[$i]),$GUI_UNCHECKED) Then GUICtrlSetState($aBtn[$i],$GUI_DISABLE) ExitLoop EndIf Next WEnd
Moderators Melba23 Posted March 30, 2015 Moderators Posted March 30, 2015 (edited) timdecker,I would do it like this:expandcollapse popup#include <file.au3> #include <GUIConstantsEx.au3> Global $a_csv[2] = [3, "Col 1,Col 2,Col 3"] ;$s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)") ;If @error Then ; MsgBox(4096, "", "No File(s) chosen") ; Exit ;Else ;_FileReadToArray($s_Path, $a_csv) GUICreate("CSV Listview", 900, 450, -1, -1) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 600, 210) $checkboxName = StringSplit($a_csv[1], ",") $iCount = $checkboxName[0] Global $aCheck[$iCount + 1] Global $mapColumn[$iCount + 1] $nextSample = GUICtrlCreateButton("Map sample submition button ", 395, 320, 180, 30) $runProg = GUICtrlCreateButton("Run Program", 700, 400, 180, 30) $button_enabled = 1 For $j = 1 To $iCount ; Store controIDs of the checkboxes $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30) $mapColumn[$j] = GUICtrlCreateButton("Map " & '"' & $checkboxName[$j] & '"' & " to input box", 150, 190 + (50 * $j), 180, 30) GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED) GUICtrlSetState($mapColumn[$j], $GUI_DISABLE) Next For $i = 2 To UBound($a_csv) - 1 $s_temp = StringReplace($a_csv[$i], ",", "|") GUICtrlCreateListViewItem($s_temp, $listview) Next ;EndIf GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case Else For $i = 1 To $iCount If $msg = $aCheck[$i] Then If GUICtrlRead($msg) = 1 Then GUICtrlSetState($mapColumn[$i], $GUI_ENABLE) Else GUICtrlSetState($mapColumn[$i], $GUI_DISABLE) EndIf ExitLoop EndIf Next EndSwitch WEnd ExitPlease ask if you have any questions. M23 Edited March 30, 2015 by Melba23 Typo MuffettsMan 1 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
timdecker Posted March 30, 2015 Author Posted March 30, 2015 @ahmet and @Melba23, thank you both for your response. I was able to get both to work as I would like. Is there an advantage to using one over the other? Thanks again!
Moderators Melba23 Posted March 30, 2015 Moderators Posted March 30, 2015 timdecker,My version only runs when a control is actioned - the other version runs through all the controls on every pass through the loop. So I would suggest that my version is better - but then you would expect me to say that anyway. M23 ahmet 1 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
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