Sign in to follow this  
Followers 0
chachew

2 radio button selector

7 posts in this topic

What i am wanting to do is to have 2 radio buttons on my form and then a start button that will perform the task associated with which ever radio button is selected. Im not sure where to go exactly, will this be an IF...Else statement? I was thinking of something to the effect of:

If $Radio1 = true then $url = "www.mysite.net"

If $Radio2 - true then $url = "www.test.site.net"

#include <IE.au3>

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

$Radio1 = ($url, "www.mysite.net")

$Radio2 = ($url, "www.test.site.net")

Func StartTest()

$IE = _IECreate($url)

$Form1 = _IEFormGetObjByName ($IE,"form1"); Name of the Login page

$Username = _IEFormElementGetObjByName ($Form1, "txtUsername"); Data that will be entered into the username field

$Password = _IEFormElementGetObjByName ($Form1, "txtPassword"); Data that will be entered into the password field

$Submit = _IEFormElementGetObjByName($Form1, "btnSubmit"); ID of the submit button

_IEFormElementSetValue ($Username, "admin")

Sleep(1000)

_IEFormElementSetValue ($Password, "password")

Sleep(1000)

_IEAction($Submit, "click"); Must use _IEAction for javascript code

EndFunc

$GUIForm1 = GUICreate("Start Login", 328, 145, 192, 124)

$Button1 = GUICtrlCreateButton("Start Testing", 8, 64, 145, 49)

;$Button2 = GUICtrlCreateButton("Stop", 168, 64, 145, 49)

$Radio1 = GUICtrlCreateRadio("Production", 24, 16, 113, 17)

$Radio2 = GUICtrlCreateRadio("Staging", 24, 40, 113, 17)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

if $nMsg = -3 Then Exit

Switch GUIGetMsg()

Case $Button1

StartTest()

EndSwitch

WEnd

Share this post


Link to post
Share on other sites



mkirkland,

An If...Else...EndIf would be better then multiple Ifs: ;)

#include <GUIConstantsEx.au3>

$url1 = "www.mysite.net"
$url2 = "www.test.site.net"

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

$GUIForm1 = GUICreate("Start Login", 328, 145, 192, 124)
$Button1 = GUICtrlCreateButton("Start Testing", 8, 64, 145, 49)
;$Button2 = GUICtrlCreateButton("Stop", 168, 64, 145, 49)
$Radio1 = GUICtrlCreateRadio("Production", 24, 16, 113, 17)
$Radio2 = GUICtrlCreateRadio("Staging", 24, 40, 113, 17)
GUISetState(@SW_SHOW)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ; Use GUICtrlRead to get the state of the radio
            If GUICtrlRead($Radio1) = 1 Then
                $url_to_use = $url1
            ; If it is not one then it must be the other!
            Else
                $url_to_use = $url2
            EndIf

            MsgBox(0, "Using", $url_to_use)

    EndSwitch

WEnd

All clear? :)

M23

P.S. When you post code please use Code tags. Put [autoit] before and [/autoit] after your posted code. :idiot:


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Melba23, i have made the changes that you suggested but when i select a radio button and click $Button1 and nothing happens exept a Msgbox pop which i have removed. I dont want the msgbox to display but when $button1 is clicked i want Func StartTest() to run $IE based on the radio button selected. Also what is the purpose of $hGUI that you added to the code?

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

Func StartTest()
$IE = _IECreate($url_to_use)
$Form1 = _IEFormGetObjByName ($IE,"form1"); Name of the Login page
$Username = _IEFormElementGetObjByName ($Form1, "txtUsername"); Data that will be entered into the username field
$Password = _IEFormElementGetObjByName ($Form1, "txtPassword"); Data that will be entered into the password field
$Submit = _IEFormElementGetObjByName($Form1, "btnSubmit"); ID of the submit button

_IEFormElementSetValue ($Username, "admin")
Sleep(1000)
_IEFormElementSetValue ($Password, "password")
Sleep(1000)
_IEAction($Submit, "click"); Must use _IEAction for javascript code
EndFunc


$urlProd = "www.mysite.net"
$urlStage = "www.test.site.net"
;$hGUI = GUICreate("Test", 500, 500)
$GUIForm1 = GUICreate("Start Login", 328, 145, 192, 124)
$Button1 = GUICtrlCreateButton("Start Testing", 8, 64, 145, 49)
;$Button2 = GUICtrlCreateButton("Stop", 168, 64, 145, 49)
$Radio1 = GUICtrlCreateRadio("Production", 24, 16, 113, 17)
$Radio2 = GUICtrlCreateRadio("Staging", 24, 40, 113, 17)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ; Use GUICtrlRead to get the state of the radio
            If GUICtrlRead($Radio1) = 1 Then
                $url_to_use = $urlProd
            ; If it is not one then it must be the other!
            Else
                $url_to_use = $urlStage
            EndIf
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

mkirkland,

That was a proof of concept script to show you how to interrogate the radios, not a full solution. You said: "Im not sure where to go exactly", so I showed you, but left it to you to integrate the concept into your own script. :idiot:

However, as you seem to want more..... :) The code I posted shows you how to get the correct URL. You then pass that URL to your function as a parameter:

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ; Use GUICtrlRead to get the state of the radio
            If GUICtrlRead($Radio1) = 1 Then
                Func StartTest($urlProd) ; Run the function with this URL
            ; If it is not one then it must be the other!
            Else
                Func StartTest($urlStage) ; Run the function with this URL
            EndIf
    EndSwitch
WEnd

Then in your function you use the parameter as follows:

Func StartTest($url) ; The parameter holds the URL we sent
$IE = _IECreate($url) ; And we use it here
.....

All clear? ;)

M23

P.S.

what is the purpose of $hGUI that you added to the code?

An oversight from the copy-paste I did of your code into my normal template. Just delete it. :idiot:

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Sorry for all the back and forth..im new to AutoIT and new to programming in any language at that..

So i now have:

Func StartTest($url_to_use)
$IE = _IECreate($url_to_use)

Is that correct because we are wanting to use the set URL value based on the radio button selection. So

If GUICtrlRead($Radio1) = 1 Then
                $url_to_use = $urlProd
Else
                $url_to_use = $urlStage
endif

It get the script to run with no errors but get no action when the $Button1 is pressed so i guess im missing something.

Edited by mkirkland

Share this post


Link to post
Share on other sites

mkirkland,

Did you actually look at the code I posted? :)

If you had you would see that I was calling the function from within the Case statements, not setting the variable. I will post it again - look for the <<<<<<<<<< lines:

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ; Use GUICtrlRead to get the state of the radio
            If GUICtrlRead($Radio1) = 1 Then
                Func StartTest($urlProd) ; Run the function with this URL <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            ; If it is not one then it must be the other!
            Else
                Func StartTest($urlStage) ; Run the function with this URL <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            EndIf
    EndSwitch
WEnd

There is no need to apologise for being new - we were all at that stage once. But please do look carefully at the answers you get - especially when you have just complained that you did not get exactly what you wanted the first time. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Informative sharing ..

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
Sign in to follow this  
Followers 0