Sign in to follow this  
Followers 0
LinuxRabbit

Need help with combo boxes

6 posts in this topic

I am trying to make a nice little RDP tool to help with the multitude of servers that I have to connect to daily. I have two combo boxes in order to separate the different sites that I have to connect to. The only problem is that after I click on the connect button I want the combo box to go back to empty.

I can make this happen but then it results in only one server being shown, the one I connected to. Can someone please help me? By the way I know the code is all frankenstein like, This is my first program written with autoit.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
HotKeySet("{esc}","exitclick")

global $comboh, $combol, $dboxh, $dBoxl
global $ini = (@ScriptDir & "\server.ini")
global $hsrvs = IniReadSection( $ini, "hsrvs")
global $lsrvs = IniReadSection( $ini, "lsrvs")
global $rdp = ("C:\windows\system32\mstsc.exe /admin /v:")

$gui = GUICreate( "LOL", 320, 23, -1, -1, BitOR($WS_BORDER,$WS_Popup), Bitor($WS_EX_APPWINDOW, $WS_EX_TOPMOST))
GUISetBkColor(0x8393a3)
GUICtrlCreateLabel ("", 0, 0, 10, 23, "",  $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, "0x3e536b")
$connect = GUICtrlCreateButton("connect", 195, 0, 50, 23, $WS_GROUP)
GUICtrlSetOnEvent(-1, "connectclick")
GUICtrlSetBkColor(-1, "0x3e536b")
$exit = GUICtrlCreateButton("exit", 248, 0, 40, 23, $WS_GROUP)
GUICtrlSetOnEvent(-1, "exitclick")
GUICtrlSetBkColor(-1, "0x3e536b")
$edit = GUICtrlCreateButton( "edit", 290, 0, 30,23, $WS_GROUP)
GUICtrlSetOnEvent(-1, "editclick")
GUICtrlSetBkColor(-1, "0x3e536b")
GUISetState()

$dBoxh = GUICtrlCreateCombo( "", 10, 0, 90, 25)
If @error Then
    MsgBox(4096, "", "Failed to read server name")
Else
    For $i = 1 To $hsrvs[0][0]
        GUICtrlSetData($dBoxh, $hsrvs[$i][1], "")
    Next
EndIf
$dboxl = GUICtrlCreateCombo( "", 100, 0, 90, 25)
If @error Then
    MsgBox(4096, "", "Failed to read server name")
Else
    For $i = 1 To $lsrvs[0][0]
        GUICtrlSetData($dBoxl, $lsrvs[$i][1], "")
    Next
EndIf

while 1
    sleep(100)
WEnd

Func connectclick()
    $comboh = GuiCtrlRead($dBoxh)
    $combol = GUICtrlRead($dboxl)
    IF $comboh Then
        Run($rdp & $comboh, "")
    Else
        Run($rdp & $combol, "")
    EndIf
    GUICtrlSetData($dBoxh, "", "")
    GUICtrlSetData($dBoxl, "", "")
    GUICtrlSetData($dBoxh, $hsrvs[2][1])
    GUICtrlSetData($dBoxl, $lsrvs[2][1])
EndFunc

func exitclick()
    exit
EndFunc

func editclick()
    ShellExecute( "server.ini","", @ScriptDir, "open")
EndFunc

Share this post


Link to post
Share on other sites



after I click on the connect button I want the combo box to go back to empty.

GUICtrlSetData($ComboBox,"")

Share this post


Link to post
Share on other sites

I guess I should have made my intentions clearer. I do not want to erase the data to be selected from the combo box, just the input field. I still want to be able to select from the array. I can always just delete what is in the field, but I would much rather have a way to reset the input box.

Share this post


Link to post
Share on other sites

LinuxRabbit,

The function you need is _GUICtrlComboBox_SetEditText from the UDF GuiComboBox.au3. I think this modified version of your code will do what you want:

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

Opt("GUIOnEventMode", 1)
HotKeySet("{esc}","exitclick")

global $comboh, $combol, $dboxh, $dBoxl
global $ini = (@ScriptDir & "\server.ini")
;global $hsrvs = IniReadSection( $ini, "hsrvs")
;global $lsrvs = IniReadSection( $ini, "lsrvs")
global $rdp = ("C:\windows\system32\mstsc.exe /admin /v:")

$gui = GUICreate( "LOL", 320, 23, -1, -1, BitOR($WS_BORDER,$WS_Popup), Bitor($WS_EX_APPWINDOW, $WS_EX_TOPMOST))
GUISetBkColor(0x8393a3)
GUICtrlCreateLabel ("", 0, 0, 10, 23, "",  $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, "0x3e536b")
$connect = GUICtrlCreateButton("connect", 195, 0, 50, 23, $WS_GROUP)
GUICtrlSetOnEvent(-1, "connectclick")
GUICtrlSetBkColor(-1, "0x3e536b")
$exit = GUICtrlCreateButton("exit", 248, 0, 40, 23, $WS_GROUP)
GUICtrlSetOnEvent(-1, "exitclick")
GUICtrlSetBkColor(-1, "0x3e536b")
$edit = GUICtrlCreateButton( "edit", 290, 0, 30,23, $WS_GROUP)
GUICtrlSetOnEvent(-1, "editclick")
GUICtrlSetBkColor(-1, "0x3e536b")
GUISetState()

$dBoxh = GUICtrlCreateCombo( "", 10, 0, 90, 25)
If @error Then
    MsgBox(4096, "", "Failed to read server name")
Else
    ;For $i = 1 To $hsrvs[0][0]
        GUICtrlSetData($dBoxh, "1|2|3|4|5|6|7", "")  ; simulate combo load
    ;Next
EndIf
$dboxl = GUICtrlCreateCombo( "", 100, 0, 90, 25)
If @error Then
    MsgBox(4096, "", "Failed to read server name")
Else
    ;For $i = 1 To $lsrvs[0][0]
        GUICtrlSetData($dBoxl, "A|B|C|D|E|F|G", "")  ; simulate combo load
    ;Next
EndIf

while 1
    sleep(100)
WEnd

Func connectclick()
    $comboh = GuiCtrlRead($dBoxh)
    $combol = GUICtrlRead($dboxl)
    IF $comboh Then
        ;Run($rdp & $comboh, "")
        MsgBox(0, "Run", $comboh) ; simulate Run
    Else
        ;Run($rdp & $combol, "")
        MsgBox(0, "Run", $comboh) ; simulate Run
    EndIf
    _GUICtrlComboBox_SetEditText($dBoxh, "") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    _GUICtrlComboBox_SetEditText($dBoxl, "") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

EndFunc

func exitclick()
    exit
EndFunc

func editclick()
    ShellExecute( "server.ini","", @ScriptDir, "open")
EndFunc

The changes are pretty easy to spot. >_<

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

Try it this way: create two new functions, like this,

Func One
    For $i = 1 To $hsrvs[0][0]
        GUICtrlSetData($dBoxh, $hsrvs[$i][1], "")
  Next
EndFunc

the second function with the other Else contents

Call these two functions, replacing the last four lines of the connectclick funtion.

This may or may not (probably not >_<) work


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Melba, thank you very much, did exactly what I needed it to do. Now I can work on making my gui look nice now that everything works.

edit: Oh yeah by the way Melba, you give the best examples out there when posting. Everything so clean and easy to see changes.

Edited by LinuxRabbit

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