airwilf Posted February 10, 2012 Posted February 10, 2012 Hi The below script is the gui im having the issue with. At the moment my script will create a different radio button for whatever the value of $x is. This part works fine, the problem is determining which button is being pressed. As the amount of radio buttons is a variable i cant use $radio1, $radio2 so i am struggling to find the answer. #include <GUIConstantsEx.au3> $Form1 = GUICreate("Form1", 615, 438, 192, 124) $Label1 = GUICtrlCreateLabel("Please choose the drive you would like to back your data upto", 48, 16, 520, 28) GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $x = 0 Dim $start = 32 do $x = $x +1 GUICtrlCreateRadio($x, 48, $start + $start * $x, 300, 33) until $x = 5 While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd
Guest Posted February 10, 2012 Posted February 10, 2012 To determine the state of the radio you use: GUICtrlRead($ControlId) If a radio button is empty the value returned by the function will be "4" otherwise if it is checked it will be "1".
airwilf Posted February 10, 2012 Author Posted February 10, 2012 Aipion How do i determine the controlid of the buttons? As i dont have $radio1 = GUICtrlCreateRadio("button1", 48, 100, 300, 33) $radio2 = GUICtrlCreateRadio("button2", 48, 200, 300, 33) and so on. Could you show me an example of using what you have suggested within my script? Thanks
water Posted February 10, 2012 Posted February 10, 2012 Please check the helpfile for GUICtrlCreateRadio. There you'll find an example that should explain everything. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Guest Posted February 10, 2012 Posted February 10, 2012 (edited) Example: #include <GUIConstantsEx.au3> $Form1 = GUICreate("Form1", 615, 438, 192, 124) $Label1 = GUICtrlCreateLabel("Please choose the drive you would like to back your data upto", 48, 16, 520, 28) GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif") $Btn1 = GUICtrlCreateButton("Next",500,400,70,25) $x = 0 Dim $start = 32 Local $Array[5] Do $x += 1 $Array[$x-1] = GUICtrlCreateRadio($x, 48, $start + $start * $x, 300, 33) Until $x = 5 GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Btn1 $SimText = "Radio Button 1: " & GUICtrlRead($Array[0]) & @CRLF $SimText &="Radio Button 2: " & GUICtrlRead($Array[1]) & @CRLF $SimText &="Radio Button 3: " & GUICtrlRead($Array[2]) & @CRLF $SimText &="Radio Button 4: " & GUICtrlRead($Array[3]) & @CRLF $SimText &="Radio Button 5: " & GUICtrlRead($Array[4]) MsgBox(0,"States",$SimText) EndSwitch WEnd Edited February 10, 2012 by Guest
airwilf Posted February 10, 2012 Author Posted February 10, 2012 Water I have had a look at the helpfile but this does not give me the answer i need,in the help from what i can see each radio button is statically assigned $radio1 ="", $radio2 = "", when done this way i can see how to check what button is being pressed. However my script is in a loop and creates buttons depending on a variable value, because i dont have $radio1 etc to enter in to GUICtrlRead i am struggling to determine what is being pressed. Thanks
Moderators Melba23 Posted February 10, 2012 Moderators Posted February 10, 2012 aitwilf,You need to learn about arrays - then you can change the number of radios very easily with just the one variable:#include <GUIConstantsEx.au3> ; Set the number of radios here Global $iRadio_Count = 5 Global $aRadio_IDs[$iRadio_Count + 1], $iStart_Y = 32 $hGUI = GUICreate("Test", 500, 500) GUICtrlCreateLabel("Please choose the drive to which you would like to backup your data", 50, 50, 500, 30) $hButton = GUICtrlCreateButton("Next", 400, 400, 70, 25) For $i = 1 To $iRadio_Count $aRadio_IDs[$i] = GUICtrlCreateRadio($i, 50, $iStart_Y * ($i + 1), 300, 30) Next GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton $sResult = "" For $i = 1 To $iRadio_Count If GUICtrlRead($aRadio_IDs[$i]) = 1 Then MsgBox(0, "You selected: ", "Radio: " & $i) ExitLoop EndIf Next EndSwitch WEndIf you are not too familiar with arrays, then I recommend the Arrays tutorial in the Wiki. 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
airwilf Posted February 10, 2012 Author Posted February 10, 2012 Aipion Thanks for that im going to tweak your code to get what im after. Just out of interest you stated earlier "If a radio button is empty the value returned by the function will be "4" otherwise if it is checked it will be "1"." is there a list that i can see exactly what values mean what? I have looked on the help but jsut seem to be going around in circles. Thanks Water and Melba23 for your advice
Guest Posted February 10, 2012 Posted February 10, 2012 (edited) You will find the list by going to the GUICtrlSetState function on the help file then below that page there will be a list called StateTableOn that list will be Variables you use them instead of numbers.And By the way there is also a function called GUICtrlGetState which the above list is for, but the GUICtrlRead($ControlId) function also uses some of them. Edited February 10, 2012 by Guest
Kyan Posted February 10, 2012 Posted February 10, 2012 aitwilf, You need to learn about arrays - then you can change the number of radios very easily with just the one variable: #include <GUIConstantsEx.au3> ; Set the number of radios here Global $iRadio_Count = 5 Global $aRadio_IDs[$iRadio_Count + 1], $iStart_Y = 32 $hGUI = GUICreate("Test", 500, 500) GUICtrlCreateLabel("Please choose the drive to which you would like to backup your data", 50, 50, 500, 30) $hButton = GUICtrlCreateButton("Next", 400, 400, 70, 25) For $i = 1 To $iRadio_Count $aRadio_IDs[$i] = GUICtrlCreateRadio($i, 50, $iStart_Y * ($i + 1), 300, 30) Next GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton $sResult = "" For $i = 1 To $iRadio_Count If GUICtrlRead($aRadio_IDs[$i]) = 1 Then MsgBox(0, "You selected: ", "Radio: " & $i) ExitLoop EndIf Next EndSwitch WEnd If you are not too familiar with arrays, then I recommend the Arrays tutorial in the Wiki. Please ask if you have any questions. M23 nice, I had the same problem with combobox, I used a bunch of "if's" thanks for the tip Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better
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