Jump to content

How To Read if radio button is selected


AlchemistZim
 Share

Recommended Posts

OK, I have a gui with 2 radio buttons, but I can't figure out how to read if the button is selected or not...I've gone through the help, and it pointed me in the right direction, but i keep getting an error when I click the go button...

This is a snippet of the code...It works here

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

    $Form2 = GUICreate("PC Refresh-Setup", 301, 301)
    $Tab1 = GUICtrlCreateTab(0, 0, 297, 297)
    
    $TabSheet1 = GUICtrlCreateTabItem("Backup")
    $F2Drop1 = GUICtrlCreateCombo("Select Share", 82, 80, 137, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1, "110-Shares-0|110-Shares-1|137-Shares-0|137-Shares-1|137-Shares-2")
    $F2Label1 = GUICtrlCreateLabel("Backup To", 123, 62, 55, 17, $SS_CENTER)
    $F2Radio1 = GUICtrlCreateRadio("Fast Wiz SP3", 35, 104, 90, 17)
    $f2Radio2 = GUICtrlCreateRadio("USMT301-x86", 176, 104, 113, 17)
    $GOBack = GUICtrlCreateButton("GO", 88, 232, 121, 33, $BS_DEFPUSHBUTTON)
    
    $TabSheet2 = GUICtrlCreateTabItem("Restore")
    $F2Drop2 = GUICtrlCreateCombo("Search Shares", 82, 80, 137, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1, "110-Shares-0|110-Shares-1|137-Shares-0|137-Shares-1|137-Shares-2")
    $F2Label2 = GUICtrlCreateLabel("Restore From", 118, 62, 65, 17, $SS_CENTER)
    $F2Radio3 = GUICtrlCreateRadio("Fast Wiz SP3", 35, 104, 90, 17)
    $Radio4 = GUICtrlCreateRadio("USMT301-x86", 176, 104, 113, 17)
    $GORest = GUICtrlCreateButton("GO", 88, 232, 121, 33, $BS_DEFPUSHBUTTON)
    
    GUICtrlSetState(-1,$GUI_SHOW)
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $GOBack
                Backup()
            Case $GORest
                Restore()
        EndSwitch
    WEnd

Func Backup()
    If GUICtrlRead($F2Radio1) = $GUI_CHECKED Then MsgBox(0,"Backup", "FastWiz is Checked")
    If GUICtrlRead($F2Radio2) = $GUI_CHECKED Then MsgBox(0,"Backup", "USMT is Checked") 
    Return
EndFunc
    

Func Restore()
    If GUICtrlRead($F2Radio1) = $GUI_CHECKED Then MsgBox(0,"Restore", "FastWiz is Checked")
    If GUICtrlRead($F2Radio2) = $GUI_CHECKED Then MsgBox(0,"Restore", "USMT is Checked")
    Return
EndFunc

This is the code from the beginning...But It Doesn't work here

Opt("TrayIconDebug",1)

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

;GUI code
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("PC Refresh-Login", 300, 300)
$F1Input1 = GUICtrlCreateInput("", 83, 131, 137, 21)
$F1Input2 = GUICtrlCreateInput("", 83, 176, 137, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$F1Label1 = GUICtrlCreateLabel("Login", 128, 62, 45, 17, $SS_CENTER)
$F1Label2 = GUICtrlCreateLabel("Username", 126, 114, 52, 17, $SS_CENTER)
$F1Label3 = GUICtrlCreateLabel("Password", 123, 159, 50, 17, $SS_CENTER)
$F1GO = GUICtrlCreateButton("GO", 88, 232, 121, 33, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;Code to look for gui changes
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Cleanup()
        Case $F1GO
            Setup()
    EndSwitch
WEnd

Func Setup()
    ;Delete Login Window
    GUIDelete($Form1)

    ;Setup window with tabs
    $Form2 = GUICreate("PC Refresh-Setup", 301, 301)
    $Tab1 = GUICtrlCreateTab(0, 0, 297, 297)
    
    $TabSheet1 = GUICtrlCreateTabItem("Backup")
    $F2Drop1 = GUICtrlCreateCombo("Select Share", 82, 153, 137, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1, "110-Shares-0|110-Shares-1|137-Shares-0|137-Shares-1|137-Shares-2")
    $F2Label1 = GUICtrlCreateLabel("Backup To", 123, 135, 55, 17, $SS_CENTER)
    $F2Radio1 = GUICtrlCreateRadio("Fast Wiz SP3", 35, 104, 90, 17)
    $F2Radio2 = GUICtrlCreateRadio("USMT301-x86", 176, 104, 113, 17)
    GUICtrlSetState(-1, $GUI_CHECKED)
    $GOBack = GUICtrlCreateButton("GO", 88, 232, 121, 33, $BS_DEFPUSHBUTTON)
    
    $TabSheet2 = GUICtrlCreateTabItem("Restore")
    $F2Drop2 = GUICtrlCreateCombo("Search Shares", 82, 153, 137, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1, "110-Shares-0|110-Shares-1|137-Shares-0|137-Shares-1|137-Shares-2")
    $F2Label2 = GUICtrlCreateLabel("Restore From", 118, 135, 65, 17, $SS_CENTER)
    $F2Radio3 = GUICtrlCreateRadio("Fast Wiz SP3", 35, 104, 90, 17)
    $F2Radio4 = GUICtrlCreateRadio("USMT301-x86", 176, 104, 113, 17)
    GUICtrlSetState(-1, $GUI_CHECKED)
    $GORest = GUICtrlCreateButton("GO", 88, 232, 121, 33, $BS_DEFPUSHBUTTON)
    
    GUICtrlSetState(-1,$GUI_SHOW)
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Cleanup()
            Case $GOBack
                Backup()
            Case $GORest
                Restore()
        EndSwitch
    WEnd
EndFunc

Func Backup()
    If GUICtrlRead($F2Radio1) = $GUI_CHECKED Then MsgBox(0,"Backup", "FastWiz is Checked")
    If GUICtrlRead($F2Radio2) = $GUI_CHECKED Then MsgBox(0,"Backup", "USMT is Checked") 
    Return
EndFunc
    

Func Restore()
    If GUICtrlRead($F2Radio3) = $GUI_CHECKED Then MsgBox(0,"Restore", "FastWiz is Checked")
    If GUICtrlRead($F2Radio4) = $GUI_CHECKED Then MsgBox(0,"Restore", "USMT is Checked")
    Return
EndFunc

What am I doing wrong???

Link to comment
Share on other sites

  • Moderators

AlchemistZim,

A radio button is selected when GUICtrlRead returns 1 - like this:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hRadio_1 = GUICtrlCreateRadio("One", 10, 10, 80, 20)
GUICtrlSetState(-1, $GUI_CHECKED)
$hRadio_2 = GUICtrlCreateRadio("Two", 90, 10, 80, 20)

$hButton = GUICtrlCreateButton("Test", 10, 100, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            If GUICtrlRead($hRadio_1) = 1 Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                MsgBox(0, "Test", "One was checked")
            Else
                MsgBox(0, "Test", "Two was checked")
            EndIf
    EndSwitch

WEnd

All clear?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

AlchemistZim,

No, it is a question of scope. You are creating the radios in function Setup(), so they are Local to that function. That means they do not exist as far as functions Backup() and Restore() are concerned. You need them to be Global variables and so visible throughout the script. :)

I suggest you read the Variables - using Global, Local and ByRef tutorial in the Wiki - it is explained in more detail there. :idiot:

Come back and ask if you have any questions after having read the tutorial. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...