niubbone Posted May 29, 2010 Posted May 29, 2010 (edited) Hi. I have multiple radio buttons in a GUI and i have to make the selectable multiple times and at the end i must check for a certain result. Looked for it in the forum but found no real help about my needs. expandcollapse popupLocal $GUITestLavoro = GUICreate("Test Colloquio Lavorativo", 468, 643, 402, 7) GUICtrlCreateLabel("TEST DI IDONEITA' AL POSTO DI LAVORO", 48, 16, 377, 28) GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif") GUICtrlCreateLabel("WorkTest", 104, 56, 282, 17) GUICtrlCreateLabel("1)", 8, 88, 17, 22) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") Local $Radio1 = GUICtrlCreateRadio("Radio1", 8, 112, 425, 17) Local $Radio2 = GUICtrlCreateRadio("Radio2", 8, 136, 425, 17) Local $Radio3 = GUICtrlCreateRadio("Radio3", 8, 160, 425, 17) Local $Radio4 = GUICtrlCreateRadio("Radio4", 8, 184, 425, 17) Local $LabelRadioDom1 = GUICtrlCreateLabel("dom1", 32, 88, 30, 17) GUICtrlCreateLabel("2)", 12, 211, 17, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") Local $Radio5 = GUICtrlCreateRadio("Radio1b", 12, 235, 425, 17) Local $Radio6 = GUICtrlCreateRadio("Radio2b", 12, 259, 425, 17) Local $Radio7 = GUICtrlCreateRadio("Radio3b", 12, 283, 425, 17) Local $Radio8 = GUICtrlCreateRadio("Radio4b", 12, 307, 425, 17) Local $LabelRadioDom2 = GUICtrlCreateLabel("dom2", 36, 211, 30, 17) GUICtrlCreateLabel("3)", 12, 340, 17, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") Local $Radio9 = GUICtrlCreateRadio("Radio1c", 12, 364, 425, 17) Local $Radio10 = GUICtrlCreateRadio("Radio2c", 12, 388, 425, 17) Local $Radio11 = GUICtrlCreateRadio("Radio3c", 12, 412, 425, 17) Local $Radio12 = GUICtrlCreateRadio("Radio4c", 12, 436, 425, 17) Local $LabelRadioDom3 = GUICtrlCreateLabel("dom3", 36, 340, 30, 17) GUICtrlCreateLabel("4)", 12, 462, 17, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") Local $Radio13 = GUICtrlCreateRadio("Radio1d", 12, 486, 425, 17) Local $Radio14 = GUICtrlCreateRadio("Radio2d", 12, 510, 425, 17) Local $Radio15 = GUICtrlCreateRadio("Radio3d", 12, 534, 425, 17) Local $Radio16 = GUICtrlCreateRadio("Radio4d", 12, 558, 425, 17) Local $LabelRadioDom4 = GUICtrlCreateLabel("dom4", 36, 462, 30, 17) Local $BottoneScappaTest = GUICtrlCreateButton("Scappa....", 8, 592, 177, 41, $WS_GROUP) Local $BottoneConsegnaTest = GUICtrlCreateButton("Consegna il test", 280, 592, 177, 41, $WS_GROUP) GUISetState(@SW_SHOW) GUISetState(@SW_HIDE,$GUICercaLavoro) ColloquioDomande() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd As you can see I have multiple radios which are answers to a precise question and I need to make multiple radios selectable (one for each question) and to test out the result at the end. A solution i found till now is to split every question in a single page with a next button, but i would like to do it kinda all togheter... To make each group of radio buttons individual i discovered that i need to make them a group. Right? Also, will this work in a similar way with checkboxes? Thanks Edited May 29, 2010 by niubbone
DW1 Posted May 29, 2010 Posted May 29, 2010 Look into GUIStartGroup(), it does exactly what you need. expandcollapse popup#include <WindowsConstants.au3> #include <Constants.au3> #include <GUIConstantsEx.au3> Local $GUITestLavoro = GUICreate("Test Colloquio Lavorativo", 468, 643, 402, 7) GUICtrlCreateLabel("TEST DI IDONEITA' AL POSTO DI LAVORO", 48, 16, 377, 28) GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif") GUICtrlCreateLabel("WorkTest", 104, 56, 282, 17) GUICtrlCreateLabel("1)", 8, 88, 17, 22) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUIStartGroup() Local $Radio1 = GUICtrlCreateRadio("Radio1", 8, 112, 425, 17) Local $Radio2 = GUICtrlCreateRadio("Radio2", 8, 136, 425, 17) Local $Radio3 = GUICtrlCreateRadio("Radio3", 8, 160, 425, 17) Local $Radio4 = GUICtrlCreateRadio("Radio4", 8, 184, 425, 17) Local $LabelRadioDom1 = GUICtrlCreateLabel("dom1", 32, 88, 30, 17) GUICtrlCreateLabel("2)", 12, 211, 17, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUIStartGroup() Local $Radio5 = GUICtrlCreateRadio("Radio1b", 12, 235, 425, 17) Local $Radio6 = GUICtrlCreateRadio("Radio2b", 12, 259, 425, 17) Local $Radio7 = GUICtrlCreateRadio("Radio3b", 12, 283, 425, 17) Local $Radio8 = GUICtrlCreateRadio("Radio4b", 12, 307, 425, 17) Local $LabelRadioDom2 = GUICtrlCreateLabel("dom2", 36, 211, 30, 17) GUICtrlCreateLabel("3)", 12, 340, 17, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUIStartGroup() Local $Radio9 = GUICtrlCreateRadio("Radio1c", 12, 364, 425, 17) Local $Radio10 = GUICtrlCreateRadio("Radio2c", 12, 388, 425, 17) Local $Radio11 = GUICtrlCreateRadio("Radio3c", 12, 412, 425, 17) Local $Radio12 = GUICtrlCreateRadio("Radio4c", 12, 436, 425, 17) Local $LabelRadioDom3 = GUICtrlCreateLabel("dom3", 36, 340, 30, 17) GUICtrlCreateLabel("4)", 12, 462, 17, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUIStartGroup() Local $Radio13 = GUICtrlCreateRadio("Radio1d", 12, 486, 425, 17) Local $Radio14 = GUICtrlCreateRadio("Radio2d", 12, 510, 425, 17) Local $Radio15 = GUICtrlCreateRadio("Radio3d", 12, 534, 425, 17) Local $Radio16 = GUICtrlCreateRadio("Radio4d", 12, 558, 425, 17) Local $LabelRadioDom4 = GUICtrlCreateLabel("dom4", 36, 462, 30, 17) Local $BottoneScappaTest = GUICtrlCreateButton("Scappa....", 8, 592, 177, 41, $WS_GROUP) Local $BottoneConsegnaTest = GUICtrlCreateButton("Consegna il test", 280, 592, 177, 41, $WS_GROUP) GUISetState(@SW_SHOW) ;~ GUISetState(@SW_HIDE, $GUICercaLavoro) ;~ ColloquioDomande() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd AutoIt3 Online Help
niubbone Posted May 29, 2010 Author Posted May 29, 2010 (edited) Perfect, both your example and Help example about that function were really helpful EDIT: After looking at help... I can't even understand how that it's done.... this is the code from help expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $button_1, $group_1, $radio_1, $radio_2, $radio_3 Local $radio_4, $radio_5, $radio_6, $input_1, $input_2 Local $radioval1, $radioval2, $msg Opt("GUICoordMode", 1) GUICreate("Radio Box Grouping Demo", 400, 280) ; Create the controls $button_1 = GUICtrlCreateButton("B&utton 1", 30, 20, 120, 40) $group_1 = GUICtrlCreateGroup("Group 1", 30, 90, 165, 160) GUIStartGroup() $radio_1 = GUICtrlCreateRadio("Radio &0", 50, 120, 70, 20) $radio_2 = GUICtrlCreateRadio("Radio &1", 50, 150, 60, 20) $radio_3 = GUICtrlCreateRadio("Radio &2", 50, 180, 60, 20) GUIStartGroup() $radio_4 = GUICtrlCreateRadio("Radio &A", 120, 120, 70, 20) $radio_5 = GUICtrlCreateRadio("Radio &B", 120, 150, 60, 20) $radio_6 = GUICtrlCreateRadio("Radio &C", 120, 180, 60, 20) GUIStartGroup() $input_1 = GUICtrlCreateInput("Input 1", 200, 20, 160, 30) $input_2 = GUICtrlCreateInput("Input 2", 200, 70, 160, 30) ; Set the defaults (radio buttons clicked, default button, etc) GUICtrlSetState($radio_1, $GUI_CHECKED) GUICtrlSetState($radio_6, $GUI_CHECKED) GUICtrlSetState($button_1, $GUI_FOCUS + $GUI_DEFBUTTON) ; Init our vars that we will use to keep track of radio events $radioval1 = 0 ; We will assume 0 = first radio button selected, 2 = last button $radioval2 = 2 GUISetState() ; In this message loop we use variables to keep track of changes to the radios, another ; way would be to use GUICtrlRead() at the end to read in the state of each control. Both ; methods are equally valid While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $button_1 MsgBox(0, "Button", "Radio " & $radioval1 & @LF & "Radio " & Chr($radioval2 + Asc("A")) & @LF & GUICtrlRead($input_1) & @LF & GUICtrlRead($input_2)) Case $msg = $radio_1 Or $msg = $radio_2 Or $msg = $radio_3 $radioval1 = $msg - $radio_1 Case $msg = $radio_4 Or $msg = $radio_5 Or $msg = $radio_6 $radioval2 = $msg - $radio_4 EndSelect WEnd EndFunc ;==>Example What this portion does???? $radioval1 = 0 ; We will assume 0 = first radio button selected, 2 = last button $radioval2 = 2 GUISetState() ; In this message loop we use variables to keep track of changes to the radios, another ; way would be to use GUICtrlRead() at the end to read in the state of each control. Both ; methods are equally valid While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $button_1 MsgBox(0, "Button", "Radio " & $radioval1 & @LF & "Radio " & Chr($radioval2 + Asc("A")) & @LF & GUICtrlRead($input_1) & @LF & GUICtrlRead($input_2)) Case $msg = $radio_1 Or $msg = $radio_2 Or $msg = $radio_3 $radioval1 = $msg - $radio_1 Case $msg = $radio_4 Or $msg = $radio_5 Or $msg = $radio_6 $radioval2 = $msg - $radio_4 EndSelect WEnd EndFunc ;==>Example I'm not sure what it does.... Edited May 29, 2010 by niubbone
PsaltyDS Posted May 31, 2010 Posted May 31, 2010 I assume you understood GuiGetMsg(), just not how the results were used. The cases for $GUI_EVENT_CLOSE and $button1 are self explanatory. The other two cases trigger for a radio button in either of the two groups. The handling takes advantage of the fact that the native AutoIt controls are created with sequential control IDs. So the second radio button's control ID will be exactly one more than the first radio button's control ID. By subtracting the control ID of the first from the one that was clicked, you get a 0-based index of which button was clicked. There are many, many other ways to handle this, so don't feel like you have to use this one. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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