Jump to content

Radio button logic


Testy
 Share

Recommended Posts

Ok,

I just simply don't understand how to apply logic in this script.

; TAB
GuiCtrlCreateTab(5, 35, 355, 130)
GuiCtrlCreateTabItem("1")
GuiCtrlCreateLabel("Region 1", 10, 10)

;R1
$Button1r1 = GUICtrlCreateButton("", 15, 65, 40, 20)

; GROUP WITH RADIO BUTTONS
GuiCtrlCreateLabel("Access Type:", 15, 118)
$radio1 = GuiCtrlCreateRadio("Live", 115, 115, 40)

GuiCtrlSetState(-1, $GUI_CHECKED)
$radio2 = GuiCtrlCreateRadio("1", 165, 115, 40)
$radio3 = GuiCtrlCreateRadio("2", 215, 115, 40)
GUICtrlCreateGroup ("",-99,-99,1,1);close group

Result needs to go here:

Case $Button1r1

Run("C:\folder\application.exe appServer=127.0.06.1 appServerPort=(PORT) app=app schema=UserSchema")

login()

Case $Button1r1
   Run("C:\folder\application.exe appServer=127.0.06.1 appServerPort=(PORT) app=app schema=UserSchema")
    login()

It escapes me. Point me in the right direction, I don't expect the work be done for me.

Again, thank you for the help.

Edited by Testy
Link to comment
Share on other sites

Do you mean something like...

Case $Button1r1
    If BitOR(GUICtrlRead($radio2),$GUI_CHECKED) = $GUI_CHECKED Then
        _exec($radio2)
    EndIf
    If BitOR(GUICtrlRead($radio3),$GUI_CHECKED) = $GUI_CHECKED Then
        _exec($radio3)
    EndIf

Func _exec($var)
    Run("C:\folder\application.exe appServer=127.0.06.1 appServerPort=(" & $var & ") app=app schema=UserSchema")
EndFunc

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Link to comment
Share on other sites

Do you mean something like...

Case $Button1r1
    If BitOR(GUICtrlRead($radio2),$GUI_CHECKED) = $GUI_CHECKED Then
        _exec($radio2)
    EndIf
    If BitOR(GUICtrlRead($radio3),$GUI_CHECKED) = $GUI_CHECKED Then
        _exec($radio3)
    EndIf

Func _exec($var)
    Run("C:\folder\application.exe appServer=127.0.06.1 appServerPort=(" & $var & ") app=app schema=UserSchema")
EndFunc
Yes, however, I think what escapes me is how to generate the $radio1 'data' of 36008 into the port $var and have the $radio1 retain it's lable "Live".

Edit: I have about 70 buttons that will use one of the 3 variables. I need to generate all of those extra line per button?

Edited by Testy
Link to comment
Share on other sites

Case $Button1r1
    If BitOR(GUICtrlRead($radio2),$GUI_CHECKED) = $GUI_CHECKED Then
        $port = 36005
        _exec($port)
    EndIf
    If BitOR(GUICtrlRead($radio3),$GUI_CHECKED) = $GUI_CHECKED Then
        $port = 36009
        _exec($port)
    EndIf

Func _exec($var)
    Run("C:\folder\application.exe appServer=127.0.06.1 appServerPort=(" & $var & ") app=app schema=UserSchema")
EndFunc

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Link to comment
Share on other sites

To answer your edited question - no. I'll give you an example in a sec.

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Link to comment
Share on other sites

Global $radio[70], $v = 115
For $i = 0 To 69 Step 1
    $radio[$i] = GUICtrlCreateRadio(36005 + $i, 165, $v, 40)
    $v = $v + 20
Next

Case $Button1r1
    For $i = 0 to 69 Step 1
        If BitOR(GUICtrlRead($radio[$i]),$GUI_CHECKED) = $GUI_CHECKED Then
            $port = 36005 + $i
            _exec($port)
        EndIf
    Next

Func _exec($var)
    Run("C:\folder\application.exe appServer=127.0.06.1 appServerPort=(" & $var & ") app=app schema=UserSchema")
EndFunc

Keep in mind, this is not the way I would go if I had 70 radios. I would use dropdowns (combos) instead. But, this will give you an idea of how to implement it without having to write so much code.

If your port numbers aren't similar or aren't chronological in order, you can always feed them into a separate variable (array) and then plug them in where appropriate.

Edited by Ealric

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Link to comment
Share on other sites

Global $radio[70], $v = 115
For $i = 0 To 69 Step 1
    $radio[$i] = GUICtrlCreateRadio(36005 + $i, 165, $v, 40)
    $v = $v + 20
Next

Case $Button1r1
    For $i = 0 to 69 Step 1
        If BitOR(GUICtrlRead($radio[$i]),$GUI_CHECKED) = $GUI_CHECKED Then
            $port = 36005 + $i
            _exec($port)
        EndIf
    Next

Func _exec($var)
    Run("C:\folder\application.exe appServer=127.0.06.1 appServerPort=(" & $var & ") app=app schema=UserSchema")
EndFunc

Keep in mind, this is not the way I would go if I had 70 radios. I would use dropdowns (combos) instead. But, this will give you an idea of how to implement it without having to write so much code.

If your port numbers aren't similar or aren't chronological in order, you can always feed them into a separate variable (array) and then plug them in where appropriate.

No, not 70 Radios, just 70 buttons spread over a number of tabs that will call one of the 3 radio options. I will upload the full script in a few mins. So you can see the full picture. so-to-speak.

Uploaded. In an edited state.

Edited by Testy
Link to comment
Share on other sites

No matter how I try, I can't get the above script to work in my script.

Here is my basic script: I just don't see the 'logic' in it, sadly enough.

#include <GUIConstants.au3>

; GUI
GuiCreate(" Helpapp", 370, 180)
GuiSetIcon("C:\Folder\Application.exe", 0)

; Version 1.0 - 2/27/08
GuiCtrlCreateLabel("v1.2", 345, 167, 136, 20)

; CONTEXT MENU
$contextMenu = GuiCtrlCreateContextMenu()
GuiCtrlCreateMenuItem("Context Menu", $contextMenu)
GuiCtrlCreateMenuItem("", $contextMenu);separator
GuiCtrlCreateMenuItem("&Properties", $contextMenu)

; TAB
GuiCtrlCreateTab(5, 35, 355, 130)
GuiCtrlCreateTabItem("1")
GuiCtrlCreateLabel("Section 1", 10, 10)

; Buttons
$Button1r1 = GUICtrlCreateButton("SL1", 15, 65, 40, 20)
$Button2r1 = GUICtrlCreateButton("SL2", 57, 65, 40, 20)
$Button3r1 = GUICtrlCreateButton("SL3", 99, 65, 40, 20)
$Button4r1 = GUICtrlCreateButton("SL4", 141, 65, 40, 20)
$Button5r1 = GUICtrlCreateButton("SL5", 183, 65, 40, 20)
$Button6r1 = GUICtrlCreateButton("SL6", 225, 65, 40, 20)
$Button7r1 = GUICtrlCreateButton("", 267, 65, 40, 20)
$Button8r1 = GUICtrlCreateButton("", 309, 65, 40, 20)

; Radio buttons
 ; live = 36008
 ; test = 36005
 ; soil = 36009

    GuiCtrlCreateLabel("App Access Type:", 15, 118)
        $radio1 = GuiCtrlCreateRadio("Live", 115, 115, 40)
    GuiCtrlSetState(-1, $GUI_CHECKED)
        $radio2 = GuiCtrlCreateRadio("Test", 165, 115, 40)
        $radio3 = GuiCtrlCreateRadio("Soil", 215, 115, 40)
    GUICtrlCreateGroup ("",-99,-99,1,1) ;close group

GUISetState(@SW_SHOW)

; Button exe's
While 1
        
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1r1
            Run("C:\Folder\Application.exe appServer=172.20.76.16 appServerPort=36008 app=apps schema=UserSchema")
            login()
            
        Case $Button2r1
            Run("C:\Folder\Application.exe appServer=10.0.13.16 appServerPort=36008 app=apps schema=UserSchema")
            login()

        Case $Button3r1
            Run("C:\Folder\Application.exe appServer=10.0.18.16 appServerPort=36008 app=apps schema=UserSchema")
            login()
            
        Case $Button4r1
            Run("C:\Folder\Application.exe appServer=10.0.20.16 appServerPort=36008 app=apps schema=UserSchema")
            login()
            
        Case $Button5r1
            Run("C:\Folder\Application.exe appServer=10.0.21.16 appServerPort=36008 app=apps schema=UserSchema")
            login()
            
        Case $Button6r1
            Run("C:\Folder\Application.exe appServer=10.0.22.16 appServerPort=36008 app=apps schema=UserSchema")
            login()
            
        Case $Button7r1
            
            
        Case $Button8r1
            
    EndSwitch
WEnd

Func login()
    WinWaitActive("Sign On")
    Sleep(1000)
    Send("user{TAB}")
    Send("password{ENTER}")
EndFunc
Link to comment
Share on other sites

I worked on this over the weekend, I tried to incorporate Ealric's ideas into it, but it gives me a case switch error. I tried to change a number of things to no avail.

Any help is appriciated.

Link to comment
Share on other sites

What about adding a function to check the radio buttons... something like this

func port_select()
    local $i = ''
    $radio1_state = GUICtrlRead($radio1)
    $radio2_state = GUICtrlRead($radio2)
    $radio3_state = GUICtrlRead($radio3)
    Select
        Case $radio1_state = $GUI_CHECKED
            $i = '36008'
        Case $radio2_state = $GUI_CHECKED
            $i = '36005'
        Case $radio_PQ_state = $GUI_CHECKED
            $i = '36009'
    EndSelect
    Return $i
EndFunc

Then just add a port_select to your script... like this

Case $Button6r1
            $port = Port_Select()
            Run("C:\Folder\Application.exe appServer=10.0.22.16 appServerPort="&$port&" app=apps schema=UserSchema")
            login()

Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

I worked on this over the weekend, I tried to incorporate Ealric's ideas into it, but it gives me a case switch error. I tried to change a number of things to no avail.

Any help is appriciated.

Try commenting out those last two case statements and see what you get. That's the two empty ones.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

#include <GUIConstants.au3>

; GUI
GuiCreate(" Helpabel", 370, 180)
GuiSetIcon(" ", 0)

;v1.0 - 2/27/08
GuiCtrlCreateLabel("v1.2", 345, 167, 136, 20)

; CONTEXT MENU
$contextMenu = GuiCtrlCreateContextMenu()
GuiCtrlCreateMenuItem("Context Menu", $contextMenu)
GuiCtrlCreateMenuItem("", $contextMenu);separator
GuiCtrlCreateMenuItem("&Properties", $contextMenu)

; TAB
GuiCtrlCreateTab(5, 35, 355, 130)
GuiCtrlCreateTabItem("1")
GuiCtrlCreateLabel("Region 1", 10, 10)

;R1
$Button1r1 = GUICtrlCreateButton("ANC", 15, 65, 40, 20)

; GROUP WITH RADIO BUTTONS
GuiCtrlCreateLabel("Abel Access Type:", 15, 118)
$radio1 = GuiCtrlCreateRadio("36008", 115, 115, 40)
GuiCtrlSetState(-1, $GUI_CHECKED)
$radio2 = GuiCtrlCreateRadio("36005", 165, 115, 40)
$radio3 = GuiCtrlCreateRadio("36009", 215, 115, 40)
GUICtrlCreateGroup ("",-99,-99,1,1) ;close group
GUISetState(@SW_SHOW)

Case $Button1r1
     $port = Port_Select()
     Run("C:\folder\application.exe appServer=10.0.18.16 appServerPort="&$port&" app=Appl schema=UserSchema")
     login()

func port_select()
    local $i = ''
    $radio1_state = GUICtrlRead($radio1)
    $radio2_state = GUICtrlRead($radio2)
    $radio3_state = GUICtrlRead($radio3)
    Select
        Case $radio1_state = $GUI_CHECKED
            $i = '36008'
        Case $radio2_state = $GUI_CHECKED
            $i = '36005'
        Case $radio_PQ_state = $GUI_CHECKED
            $i = '36009'
    EndSelect
    Return $i
EndFunc

Func login()
    WinWaitActive("Sign On");
    Sleep(1000)
    Send("user{TAB}")
    Send("password{ENTER}")
EndFunc

When I run that code I get this error:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "E:\Var Button Tester 01.au3"

E:\Var Button Tester 01.au3 (33) : ==> "Case" statement with no matching "Select"or "Switch" statement.:

Case $Button1r1

Link to comment
Share on other sites

When I run that code I get this error:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "E:\Var Button Tester 01.au3"

E:\Var Button Tester 01.au3 (33) : ==> "Case" statement with no matching "Select"or "Switch" statement.:

Case $Button1r1

You're missing your proper GuiGetMsg() loop construction

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Button1r1
            $port = Port_Select()
            MsgBox(0,"PORT",$port) ; just to see that we got what we want
            Run("C:\folder\application.exe appServer=10.0.18.16 appServerPort="&$port&" app=Appl schema=UserSchema")
            login()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by ResNullius
Link to comment
Share on other sites

You're missing your proper GuiGetMsg() loop construction

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Button1r1
            $port = Port_Select()
            MsgBox(0,"PORT",$port) ; just to see that we got what we want
            Run("C:\folder\application.exe appServer=10.0.18.16 appServerPort="&$port&" app=Appl schema=UserSchema")
            login()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
When I add that, I get no error message, but it does not call up the application when the button is pressed. No matter the state of the radio button.
Link to comment
Share on other sites

When I add that, I get no error message, but it does not call up the application when the button is pressed. No matter the state of the radio button.

Are you sure your Run() command is correct?

Try this and report what happens. Answer yes if notepad runs and asks you if you wnat to create a new file.

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Button1r1
            $port = Port_Select()
            MsgBox(0,"PORT",$port) ; just to see that we got what we want
            ;Run("C:\folder\application.exe appServer=10.0.18.16 appServerPort="&$port&" app=Appl schema=UserSchema")
            Run("Notepad appServer=10.0.18.16 appServerPort="&$port&" app=Appl schema=UserSchema")
            ;login()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

Are you sure your Run() command is correct?

Try this and report what happens. Answer yes if notepad runs and asks you if you wnat to create a new file.

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Button1r1
            $port = Port_Select()
            MsgBox(0,"PORT",$port) ; just to see that we got what we want
            ;Run("C:\folder\application.exe appServer=10.0.18.16 appServerPort="&$port&" app=Appl schema=UserSchema")
            Run("Notepad appServer=10.0.18.16 appServerPort="&$port&" app=Appl schema=UserSchema")
            ;login()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
No. It does not come up.

While 1

$msg = GUIGetMsg()

Switch $msg

Case $Button1r1

$port = Port_Select()

MsgBox(0,"PORT",$port) ; just to see that we got what we want

;Run("C:\folder\application.exe appServer=10.0.18.16 appServerPort="&$port&" app=Appl schema=UserSchema")

Run("Notepad.exe")

;login()

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

Link to comment
Share on other sites

I noticed ResNullius used Notepad, and you used Notepad.exe in your run statement... :)

Doesn't matter when I change mine to "notepad.exe" it still works

@Testy,

Do you get the MsgBox popup with the port number?

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