Jump to content

How to to check if radio is checked?


Recommended Posts

How to check if radio is checked? I tried GUICtrlRead() but it returns 0 as I remember it should return 1 or 4, but it doesn't anymore.

How to check which radio is checked? Can I make dynamic function for all radio buttons or I have to make IF sentence for every single radio?

$Form0 = GUICreate("Select Language", 200, 140)
$nextbtn = GUICtrlCreateButton("&Next >",90,110,75,20)
$cancelbtn = GUICtrlCreateButton("&Cancel",10,110,75,20)
$LngdirSel = GUICtrlCreateButton("Browse",120,80,70,20)
$lngfile = GUICtrlCreateInput("",15,80,95,20)
GUICtrlCreateGroup("Select Language",10,5,180,100)
$LNGEnglish = GUICtrlCreateRadio("English",15,20,140,20)
GUICtrlSetState($LNGEnglish,$GUI_CHECKED)
$LNGEstonian = GUICtrlCreateRadio("Eesti",15,40,140,20)
$LNGOther = GUICtrlCreateRadio("Other",15,60,140,20)    
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nextbtn
            GUIDelete($Form0)
            MsgBox(1,1,GUICtrlRead($LNGEnglish))
            $LNG = StringSplit(FileRead(@ScriptDir&"\english.txt"),@CRLF,1)
            _InstallGUI()
            ExitLoop
;~      Case    
    EndSwitch   
WEnd

edited

Link to comment
Share on other sites

How to check if radio is checked? I tried GUICtrlRead() but it returns 0 as I remember it should return 1 or 4, but it doesn't anymore.

How to check which radio is checked? Can I make dynamic function for all radio buttons or I have to make IF sentence for every single radio?

$Form0 = GUICreate("Select Language", 200, 140)
$nextbtn = GUICtrlCreateButton("&Next >",90,110,75,20)
$cancelbtn = GUICtrlCreateButton("&Cancel",10,110,75,20)
$LngdirSel = GUICtrlCreateButton("Browse",120,80,70,20)
$lngfile = GUICtrlCreateInput("",15,80,95,20)
GUICtrlCreateGroup("Select Language",10,5,180,100)
$LNGEnglish = GUICtrlCreateRadio("English",15,20,140,20)
GUICtrlSetState($LNGEnglish,$GUI_CHECKED)
$LNGEstonian = GUICtrlCreateRadio("Eesti",15,40,140,20)
$LNGOther = GUICtrlCreateRadio("Other",15,60,140,20)    
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nextbtn
            GUIDelete($Form0)
            MsgBox(1,1,GUICtrlRead($LNGEnglish))
            $LNG = StringSplit(FileRead(@ScriptDir&"\english.txt"),@CRLF,1)
            _InstallGUI()
            ExitLoop
;~      Case    
    EndSwitch   
WEnd
You deleted the GUI (and the control) before reading it.

:)

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
Link to comment
Share on other sites

Maybe...

$Form0 = GUICreate("Select Language", 200, 140)
$nextbtn = GUICtrlCreateButton("&Next >", 90, 110, 75, 20)
$cancelbtn = GUICtrlCreateButton("&Cancel", 10, 110, 75, 20)
$LngdirSel = GUICtrlCreateButton("Browse", 120, 80, 70, 20)
$lngfile = GUICtrlCreateInput("", 15, 80, 95, 20)
GUICtrlCreateGroup("Select Language", 10, 5, 180, 100)
$LNGEnglish = GUICtrlCreateRadio("English", 15, 20, 140, 20)
GUICtrlSetState($LNGEnglish, $GUI_CHECKED)
$LNGEstonian = GUICtrlCreateRadio("Eesti", 15, 40, 140, 20)
$LNGOther = GUICtrlCreateRadio("Other", 15, 60, 140, 20)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nextbtn
            If _IsChecked($LNGEnglish) Then
                MsgBox(1, 1, GUICtrlRead($LNGEnglish))
                $LNG = StringSplit(FileRead(@ScriptDir & "\english.txt"), @CRLF, 1)
                _InstallGUI()
                ExitLoop
            ElseIf _IsChecked($LNGEstonian) Then
                ; do something here
            ElseIf _IsChecked($LNGOther) Then
                ; do other something here
            Else
                MsgBox(4096, "Error", " No Language was checked", 5)
            EndIf

            
;~   Case
    EndSwitch
WEnd
GUIDelete($Form0)

Func _IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

8)

NEWHeader1.png

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...