Sign in to follow this  
Followers 0
kiffab

AutoIt combo box item selection

5 posts in this topic

Hello

AutoIt noob here... looking for some assistance with an app I've built.

I'm replacing my input boxes with a combo box with several items listed. To do this, I used the code:

$hostname = _GUICtrlComboBox_Create($myGUI, "item1|item2|item3", 110, 70, 170, 20)

I can then click on the drop down arrow and choose one of the items. However, I'm unsure how I could then write the contents of the box to the file. Trying to display the $hostname output in a msgbox results in either a blank string or a 0.

Another strange problem I have is that some I can click on all but 1 of my input boxes. I have no idea why. :)

Thanks in advance for any help :)

Share this post


Link to post
Share on other sites



kiffab,

Welcome to the AutoIt forum. :)

You need to use GUICtrlRead to get the contents of your combo - and then FileWrite or FileWriteLine to get that value into a file.

As to the recalcitrant input box, please post your code and we will take a look - it is a bit difficult to debug at distance as the crystal balls are not too reliable these days. :P

When you post your code please use Code tags - just put [autoit] before and [/autoit] after your posted code. :)

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

Thanks for the prompt response.

Here you go...

Notice file path 3 is not clickable. Not sure why. I also try to read the contents of hostname but it says "0".

#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <StaticConstants.au3>

Global $btn[5]

GUI()

Func GUI()
    Local $myGUI, $msg, $hostname, $database, $server, $username, $password, $fp1, $fp2, $fp3, $font, $sIni, $msgbox

    $myGUI = GUICreate("app", 500, 400)
    GUISetBkColor(0xe9CADC3)
    GUISetFont(8, 1, 3, "verdana")

    GUICtrlCreateLabel("Hostname", 60, 10, 60, 20)
    $hostname = _GUICtrlComboBox_Create($myGUI, "Server1|Server2|Server3", 20, 30, 120, 20)

    GUICtrlCreateLabel("Username", 180, 10, 60, 20)
    $logon = _GUICtrlComboBox_Create($myGUI, "user1|user2|user3", 150, 30, 120, 20)

    GUICtrlCreateLabel("Password", 310, 10, 60, 20)
    $password = GUICtrlCreateInput("", 280, 30, 120, 20)

    GUICtrlCreateLabel("Database", 60, 75, 120, 20)
    $database = _GUICtrlComboBox_Create($myGUI, "db1|db2|db3", 110, 70, 170, 20)

    GUICtrlCreateLabel("FilePath1", 30, 225, 100, 20)
    $fp1 = GUICtrlCreateInput("", 110, 225, 230, 20)

    GUICtrlCreateLabel("FilePath2", 30, 245, 100, 20)
    $fp2 = GUICtrlCreateInput("", 110, 245, 230, 20)

    GUICtrlCreateLabel("FilePath3", 30, 265, 315, 20)
    $fp3 = GUICtrlCreateInput("", 110, 265, 230, 20)

    $btn[0] = GUICtrlCreateButton("read hostname", 370, 185, 80, 30)
    $btn[1] = GUICtrlCreateButton("button2", 370, 215, 80, 30)
    $btn[2] = GUICtrlCreateButton("button3", 370, 245, 80, 30)
    $btn[3] = GUICtrlCreateButton("button4", 370, 275, 80, 30)
    $btn[4] = GUICtrlCreateButton("Exit", 370, 305, 80, 30)

    GUISetState()
    Do
        $msg = GUIGetMsg()

        If $msg = $btn[0] Then
            msgBox(4160, "box",GUICtrlRead($hostname))
        EndIf

        If $msg = $btn[4] Then
            Exit
        EndIf

    Until $msg = $GUI_EVENT_CLOSE

    ;GUISetState(@SW_SHOW, $myGUI)

EndFunc

Share this post


Link to post
Share on other sites

kiffab,

Pretty simple to sort that one out for you! :)

- 1. I would recommend that you use the native functions to create controls if you can - it makes everything much easier. You were using the UDF combo creation function, which means you have to use the other UDF functions to interact with it. If you create your controls with the native functions, you can use the native functions to interact. Keep the UDF functions for when you need the additional functionality they offer in more advanced scripts. :P

- 2. You could not click your input as the label was 315 pixels wide and so overlapped with the input. If you have overlapping controls, AutoIt does not know which you are actioning and so refuses to action either! ;)

Here is the amended code - look for the <<<<<<<<<<<< lines:

#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <StaticConstants.au3>

Global $btn[5]

GUI()

Func GUI()
    Local $myGUI, $msg, $hostname, $database, $server, $username, $password, $fp1, $fp2, $fp3, $font, $sIni, $msgbox

    $myGUI = GUICreate("app", 500, 400)
    GUISetBkColor(0xe9CADC3)
    GUISetFont(8, 1, 3, "verdana")

    GUICtrlCreateLabel("Hostname", 60, 10, 60, 20)
    $hostname = GUICtrlCreateCombo("", 20, 30, 120, 20) ; <<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetData(-1, "Server1|Server2|Server3") ; <<<<<<<<<<<<<<<<<<<<<<<<<

    GUICtrlCreateLabel("Username", 180, 10, 60, 20)
    $logon = GUICtrlCreateCombo("", 150, 30, 120, 20) ; <<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetData(-1, "user1|user2|user3") ; <<<<<<<<<<<<<<<<<<<<<<<<<

    GUICtrlCreateLabel("Password", 310, 10, 60, 20)
    $password = GUICtrlCreateInput("", 280, 30, 120, 20)

    GUICtrlCreateLabel("Database", 60, 75, 120, 20)
    $database = GUICtrlCreateCombo("", 110, 70, 170, 20) ; <<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetData(-1, "db1|db2|db3") ; <<<<<<<<<<<<<<<<<<<<<<<<<

    GUICtrlCreateLabel("FilePath1", 30, 225, 100, 20)
    $fp1 = GUICtrlCreateInput("", 110, 225, 230, 20)

    GUICtrlCreateLabel("FilePath2", 30, 245, 100, 20)
    $fp2 = GUICtrlCreateInput("", 110, 245, 230, 20)

    GUICtrlCreateLabel("FilePath3", 30, 265, 100, 20) ; <<<<<<<<<<<<<<<<<<<<<<<<<
    $fp3 = GUICtrlCreateInput("", 110, 265, 230, 20)

    $btn[0] = GUICtrlCreateButton("read hostname", 370, 185, 80, 30)
    $btn[1] = GUICtrlCreateButton("button2", 370, 215, 80, 30)
    $btn[2] = GUICtrlCreateButton("button3", 370, 245, 80, 30)
    $btn[3] = GUICtrlCreateButton("button4", 370, 275, 80, 30)
    $btn[4] = GUICtrlCreateButton("Exit", 370, 305, 80, 30)

    GUISetState()
    Do
        $msg = GUIGetMsg()

        If $msg = $btn[0] Then
            msgBox(4160, "box",GUICtrlRead($hostname))
        EndIf

        If $msg = $btn[4] Then
            Exit
        EndIf

    Until $msg = $GUI_EVENT_CLOSE

    ;GUISetState(@SW_SHOW, $myGUI)

EndFunc

Note the use of GUICtrlSetData to fill the combos. :D

Please ask if you have any questions. :)

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

Thanks very much for showing me the error of my ways!!

Tested - working perfectly.

Cheers :)

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