Jump to content
DigDeep

Combination of Radio Buttons and InputBox

Recommended Posts

DigDeep

Hi,

I am definitely doing something wrong here that I am not able to figure out.

I have the below GUI which has 2 radio buttons, 1 Input box and 1 OK Button.

  1. If OK button is pressed without selecting Radio and InputBox, it should throw error. (both radio and input text should be filled in mandatory, else error)
  2. If OK button is pressed by selecting both Radio and Input Text, then show the msgbox with Input Text and run the func of the Radio selected.

 

Can someone help please?

 

#Region
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $OK = 9999

#Region
$Form2 = GUICreate("GUI", 496, 238, 1009, 394)
$Input = GUICtrlCreateInput("", 40, 176, 241, 21)
$Radio1 = GUICtrlCreateRadio("Option 1", 40, 40, 241, 17)
$Radio2 = GUICtrlCreateRadio("Option 2", 40, 80, 241, 17)
$OK = GUICtrlCreateButton("OK", 336, 176, 75, 25, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
#EndRegion

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $OK

            Switch GUICtrlRead($Input)
                Case $Radio1
                    Step1()

                Case $Radio2
                    Step2()

                Case ""
                    MsgBox(16, "", "Select an option and click OK.")
            EndSwitch
    EndSwitch
WEnd


Func Step1()
    MsgBox(0, '', 'Running steps from Option 1')
EndFunc   ;==>Step1

Func Step2()
    MsgBox(0, '', 'Running steps from Option 2')
EndFunc   ;==>Step2

 

Edited by DigDeep

Share this post


Link to post
Share on other sites
kylomas

DigDeep,

One of many ways to do this...

#Region
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $OK = 9999

#Region
$Form2 = GUICreate("GUI", 496, 238, 1009, 394)
$Input = GUICtrlCreateInput("", 40, 176, 241, 21)
$Radio1 = GUICtrlCreateRadio("Option 1", 40, 40, 241, 17)
$Radio2 = GUICtrlCreateRadio("Option 2", 40, 80, 241, 17)
$OK = GUICtrlCreateButton("OK", 336, 176, 75, 25, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
#EndRegion

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $OK

            If GUICtrlRead($Input) = '' Then
                GUICtrlSetState($Input, $gui_focus)
                MsgBox(17, 'ERROR', 'Input required!', 3)
                ContinueLoop
            EndIf
            If BitAND(GUICtrlRead($Radio1), $GUI_CHECKED) = $GUI_CHECKED Then Step1()
            If BitAND(GUICtrlRead($Radio2), $GUI_CHECKED) = $GUI_CHECKED Then Step2()

    EndSwitch
WEnd


Func Step1()
    MsgBox(0, '', 'Running steps from Option 1')
EndFunc   ;==>Step1

Func Step2()
    MsgBox(0, '', 'Running steps from Option 2')
EndFunc   ;==>Step2

kylomas

edit:

another way...

#Region
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $OK = 9999

#Region
$Form2 = GUICreate("GUI", 496, 238, 1009, 394)
$Input = GUICtrlCreateInput("", 40, 176, 241, 21)
$Radio1 = GUICtrlCreateRadio("Option 1", 40, 40, 241, 17)
$Radio2 = GUICtrlCreateRadio("Option 2", 40, 80, 241, 17)
GUISetState(@SW_SHOW)
#EndRegion

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Radio1

            If GUICtrlRead($Input) = '' Then
                GUICtrlSetState($Input, $gui_focus)
                MsgBox(17, 'ERROR', 'Input required!', 3)
                ContinueLoop
            EndIf
            Step1()

        Case $Radio2

            If GUICtrlRead($Input) = '' Then
                GUICtrlSetState($Input, $gui_focus)
                MsgBox(17, 'ERROR', 'Input required!', 3)
                ContinueLoop
            EndIf
            Step2()

    EndSwitch
WEnd


Func Step1()
    MsgBox(0, '', 'Running steps from Option 1')
EndFunc   ;==>Step1

Func Step2()
    MsgBox(0, '', 'Running steps from Option 2')
EndFunc   ;==>Step2

 

Edited by kylomas
  • Like 1

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.