3mustgetbeers Posted February 22, 2010 Posted February 22, 2010 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 expandcollapse popup#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" ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Moderators Melba23 Posted February 22, 2010 Moderators Posted February 22, 2010 3mustgetbeers,Welcome to the AutoIt forum. 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
3mustgetbeers Posted February 22, 2010 Author Posted February 22, 2010 Ah yes! Its pretty obvious now you point it out, telling it to read the dropdown, not just what it is. Cheers mate! Andy
Moderators Melba23 Posted February 22, 2010 Moderators Posted February 22, 2010 3mustgetbeers, A pleasure. Young's Special please! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now