Jump to content

How are Radio Button Selections returned?


Recommended Posts

I am trying to get the results of a radio button selection. I have tried implementing sample scripts but to no avail.

Can someone tell / show me what I am doing wrong?

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Local $bSelect1
Local $bSelect2
Local $bSelect3

SelectButton()  ;The results of SelectButton is not being returned
        MsgBox(0,"","Select1 is "& $bSelect1 & ". Select2 is "& $bSelect2 & ". Select3 is "& $bSelect3 & ".")

Func SelectButton()
    Local $hGUI = GUICreate("SGX4CP Tests", 300, 300)
    GUISetState()

    Local $bSelect1 = GUICtrlCreateRadio("Select 1", 10, 160)
    Local $bSelect2 = GUICtrlCreateRadio("Select 2", 10, 190)
    Local $bSelect3 = GUICtrlCreateRadio("Select 3", 10, 220)

    ; Set TestSelectForever as the default radio button
    GUICtrlSetState($bSelect1, $GUI_CHECKED)
    Local $idClose = GUICtrlCreateButton("Start", 120,250)
    Local $idMsg
    While 1
        $idMsg = GUIGetMsg()
        Select

             Case $idMsg = $GUI_EVENT_CLOSE Or $idMsg = $idClose
                ExitLoop

            Case $idMsg = $bSelect1  And BitAND(GUICtrlRead($bSelect1), $GUI_CHECKED) = $GUI_CHECKED
                MsgBox(0,"","Select1")
            Case $idMsg = $bSelect2 And BitAND(GUICtrlRead($bSelect2), $GUI_CHECKED) = $GUI_CHECKED
                MsgBox(0,"","Select2")
            Case $idMsg = $bSelect3 And BitAND(GUICtrlRead($bSelect3), $GUI_CHECKED) = $GUI_CHECKED
                MsgBox(0,"","Select3")

;           GUICtrlRead($hGUI)
            EndSelect
        WEnd
        MsgBox(0,"","Select1 is "& $bSelect1 & ". Select2 is "& $bSelect2 & ". Select3 is "& $bSelect3 & ".")   ; Why is this returning numbers?
EndFunc

 

Link to comment
Share on other sites

The only "error" I see is the double definition of the variables $bSelectx.
Use:

$bSelect1 = GUICtrlCreateRadio("Select 1", 10, 160)
$bSelect2 = GUICtrlCreateRadio("Select 2", 10, 190)
$bSelect3 = GUICtrlCreateRadio("Select 3", 10, 220)

 

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

 

Link to comment
Share on other sites

Hi Jibberish,

First I took your Start Button and wrapped an If Else Endif statement into it, to read the results of the Radio button.

I've also cleaned your script up. Took away your function. No need to wrap it in a func.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("SGX4CP Tests", 300, 300, 192, 124)
$bSelect1 = GUICtrlCreateRadio("Select 1", 10, 160)
$bSelect2 = GUICtrlCreateRadio("Select 2", 10, 190)
$bSelect3 = GUICtrlCreateRadio("Select 3", 10, 220)
$idClose = GUICtrlCreateButton("Start", 120, 250)
GUISetState(@SW_SHOW)
; Set TestSelectForever as the default radio button
GUICtrlSetState($bSelect1, $GUI_CHECKED)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bSelect1
            MsgBox(0, "", "Select1")

        Case $bSelect2
            MsgBox(0, "", "Select2")

        Case $bSelect3
            MsgBox(0, "", "Select3")

        Case $idClose
            $bSelect1 = GUICtrlRead($bSelect1)
            $bSelect2 = GUICtrlRead($bSelect2)
            $bSelect3 = GUICtrlRead($bSelect3)


            If $bSelect1 = 1 Then
                $Radio1 = String("checked")
            Else
                $Radio1 = String("not checked")
            EndIf

            If $bSelect2 = 1 Then
                $Radio2 = String("checked")
            Else
                $Radio2 = String("not checked")
            EndIf

            If $bSelect3 = 1 Then
                $Radio3 = String("checked")
            Else
                $Radio3 = String("not checked")
            EndIf
            MsgBox(0, "Results", "Select1 is " & $Radio1 & ". Select2 is " & $Radio2 & ". Select3 is " & $Radio3 & ".")
            ExitLoop
    EndSwitch
WEnd

 

Edited by Skeletor

Kind Regards
Skeletor

"Coffee: my defense against going postal."

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...