Sign in to follow this  
Followers 0
3mustgetbeers

Combo Box

4 posts in this topic

Hi All,

Newbie here, so all help is grately appreciated - learning curve for me codeing - even if it just to write my program a little neater!

Okay, introductions aside, I am writing a code that will present a user with a GUI:: User select a server from a dropdown menu (combobox?) then they can either connect to it via RDP or VNC. So the RDP button should 'read' what is selected in the dropdown, then run the relevant function that opens mstsc.exe, sends the correct IP and connects. At least that is how I would imagine it to happen - there is probably a much simpler way.

I keep getting the error 'Variable used without being declared.: Run($ServerChoice)' though I thought it was declared in the IF statement?

Anyway, below is the code I have already, any suggestions/improvements/hints/critique/the solution is very much appreciated!

Thanks

Andy

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Creates the GUI
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

$Connecto = GUICreate("Connector", 268, 107, 342, 126)
    GUISetBkColor(0xFFFFFF)

$Label1 = GUICtrlCreateLabel("Select a server to connect to:", 8, 8, 250, 27)
    GUICtrlSetFont(-1, 14, 400, 0, "Tahoma")

$DropDown = GUICtrlCreateCombo("Server...", 8, 40, 249, 25)
    GUICtrlSetData($DropDown, "Server A|Server B", "Server...")

$RDP = GUICtrlCreateButton("RDP", 8, 72, 75, 25, $WS_GROUP)

$VNC = GUICtrlCreateButton("VNC", 96, 72, 75, 25, $WS_GROUP)

$Exit = GUICtrlCreateButton("Exit", 184, 72, 75, 25, $WS_GROUP)

GUISetState(@SW_SHOW)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Sets conditions of the GUI
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        ; Sets Combo box
        Case $DropDown

        ; Sets RDP button to connect to selected server
        Case $RDP
            if $DropDown= ("Server...") Then $ServerChoice=ShowError()
            if $DropDown= ("Server A")  Then $ServerChoice=ServerA()
            if $DropDown= ("Server B")  Then $ServerChoice=ServerB()
            Run($ServerChoice)

        ; Sets VNC button to connect to selected server
        Case $VNC

        ; Sets Exit button to exit GUI
        Case $Exit
            Exit
    EndSwitch
WEnd
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Functions
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Func ServerA()
    Run("C:\Windows\system32\mstsc.exe")
    WinWaitActive("Remote Desktop Connection")
    SLeep(200)
    send("!o")
    Sleep(400)
    send(""& $ServerA_IP)
    send("{TAB}"& $User)
    Send("!n")
    ; wait till active, press esc, sleep, press ctrl alt del, send username & password from ini, press enter

EndFunc

Func ServerB()
    Run("C:\Windows\system32\mstsc.exe")
    WinWaitActive("Remote Desktop Connection")
    SLeep(200)
    send("!o")
    Sleep(400)
    send(""& $ServerB_IP)
    send("{TAB}"& $User)
    Send("!n")
EndFunc
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; List of IPs
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ServerA_IP="192.168.1.1"
$ServerB_IP="192.168.0.1"

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites



3mustgetbeers,

Welcome to the AutoIt forum. :mellow:

You need to read the content of the combo - at the moment you are just getting the ControlID. Change the 3 lines to look like this:

if GUICtrlRead($DropDown) = ("Server A")  Then $ServerChoice=ServerA()

Please ask if anything is unclear.

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

Ah yes! Its pretty obvious now you point it out, telling it to read the dropdown, not just what it is.

Cheers mate!

Andy

Share this post


Link to post
Share on other sites

3mustgetbeers,

A pleasure. Young's Special please! :mellow:

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

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