Jump to content
Sign in to follow this  
Fran

_GUICtrlComboBoxEx_Create

Recommended Posts

Fran

Hi there...

I'm pretty new to AutoIt, so please excuse me for my silly questions :blink:

I've created a GUI with a combobox. I get the lines for the combobox from a text file. How do I get the result in the form of the selected text?

You'll see I've added a msgbox to display my result, but what I want is if the person selects "Azure", the msgbox must echo "Azure".

I have a attached my script.

Looking forward to adding another item to my "things-I-know-now-that-I-didn't-know-before" -list.

Cheers!

Fran

CreateContentUpdate.au3

Edited by Fran

Share this post


Link to post
Share on other sites
Melba23

Fran,

Welcome to the AutoIt forum. :blink:

There are quite a few things you might want to add to your "things-I-know-now-that-I-didn't-know-before" list in this shortened version of your script. :P

- 1. Use _FileListToArray to get a list of the files in a folder - much easier than FileFindFirst/NextFile.

- 2. Use the built-in combo rather than the UDF version - much less trouble to work with.

- 3. Switch can accept multiple versions of a Case - saves typing!

- 4. You can use the MsgBox directly in the If statement.

- 5. And you use GUICtrlRead to get the selected value of a built-in combo!

Here is the script - look for the <<<<<<<<<<<<<<<<< lines:

; Script Start - Add your code below here
;#RequireAdmin

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <array.au3>
#include <file.au3>
#include <GUIComboBox.au3>
#include <GUIComboBoxEx.au3>

Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)

; Shows the filenames of all files in the current directory.
$aFileList = _FileListToArray("ContentUpdates\mphoto\", "*.*", 1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
If @error Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf
; Put array into a string
$sFileList = "|" & _ArrayToString($aFileList, "|", 1)

_Main()

Func _Main()
    $gui = GUICreate("Create exe", 460, 250)

    $hCombo = GUICtrlCreateCombo("", 40, 100, 380, 296) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetData($hCombo, $sFileList)

    $butNext = GUICtrlCreateButton("Next", 350, 210, 90, 30, BitOR($BS_DEFPUSHBUTTON, $BS_NOTIFY))
    $butCancel = GUICtrlCreateButton("Cancel", 250, 210, 90, 30, BitOR($BS_DEFPUSHBUTTON, $BS_NOTIFY))

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $butCancel ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                If MsgBox(8196, "Cancel setup", "Are you sure you want to cancel this operation?") = 6 Then Exit ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            Case $butNext
                MsgBox(4096, "result", "You have chosen: " & GUICtrlRead($hCombo)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        EndSwitch
    WEnd

EndFunc   ;==>_Main

I hope it all makes sense - please ask if not. ;)

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
Fran

Wow, thanks!

This helps me a great deal.

Have a good one!

Fran,

Welcome to the AutoIt forum. :blink:

There are quite a few things you might want to add to your "things-I-know-now-that-I-didn't-know-before" list in this shortened version of your script. :P

- 1. Use _FileListToArray to get a list of the files in a folder - much easier than FileFindFirst/NextFile.

- 2. Use the built-in combo rather than the UDF version - much less trouble to work with.

- 3. Switch can accept multiple versions of a Case - saves typing!

- 4. You can use the MsgBox directly in the If statement.

- 5. And you use GUICtrlRead to get the selected value of a built-in combo!

Here is the script - look for the <<<<<<<<<<<<<<<<< lines:

; Script Start - Add your code below here
;#RequireAdmin

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <array.au3>
#include <file.au3>
#include <GUIComboBox.au3>
#include <GUIComboBoxEx.au3>

Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)

; Shows the filenames of all files in the current directory.
$aFileList = _FileListToArray("ContentUpdates\mphoto\", "*.*", 1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
If @error Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf
; Put array into a string
$sFileList = "|" & _ArrayToString($aFileList, "|", 1)

_Main()

Func _Main()
    $gui = GUICreate("Create exe", 460, 250)

    $hCombo = GUICtrlCreateCombo("", 40, 100, 380, 296) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetData($hCombo, $sFileList)

    $butNext = GUICtrlCreateButton("Next", 350, 210, 90, 30, BitOR($BS_DEFPUSHBUTTON, $BS_NOTIFY))
    $butCancel = GUICtrlCreateButton("Cancel", 250, 210, 90, 30, BitOR($BS_DEFPUSHBUTTON, $BS_NOTIFY))

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $butCancel ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                If MsgBox(8196, "Cancel setup", "Are you sure you want to cancel this operation?") = 6 Then Exit ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            Case $butNext
                MsgBox(4096, "result", "You have chosen: " & GUICtrlRead($hCombo)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        EndSwitch
    WEnd

EndFunc   ;==>_Main

I hope it all makes sense - please ask if not. ;)

M23

Share this post


Link to post
Share on other sites
Melba23

Fran,

Glad I could help. ;)

A small thing - when you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. :blink:

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
Fran

:blink: - like this?

Just wanted to let you know you've helped me tremendously. Not only with this specific script, but also with my other scripts.

They are shorter by at least 20%!

Much less typing ;)

You rock!

Can I ask one more question?

How would you manage a "back" button in a GUI... as there is no GOTO function.

Fran

Share this post


Link to post
Share on other sites
Melba23

Fran,

like this?

Exactly! :blink:

Who needs GoTo? You manage multiple GUIs in GetMessage mode by using the "advanced" parameter in GUIGetMsg like this:

#include <GUIConstantsEx.au3>

; We need to declare this early becasue we check it even if GUI_2 does not exist
Global $hGUI_2 = 9999

; Create GUI_1
$hGUI_1 = GUICreate("GUI 1", 500, 500)
$hButton_1 = GUICtrlCreateButton("New GUI", 10, 10, 80, 30)
GUISetState()

While 1

    ; Use GUIGetMsg with advanced parameter to see which GUI is sending message
    $aMsg = GUIGetMsg(1)
    ; Check which GUI
    Switch $aMsg[1]
        Case $hGUI_1
            ; Check which message GUI_1 sent
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $hButton_1
                    ; Create GUI_2
                    $hGUI_2 = GUICreate("GUI 2", 200, 200)
                    $hButton_2 = GUICtrlCreateButton("Back", 10, 10, 80, 30)
                    GUISetState()
            EndSwitch
        Case $hGUI_2
            ; Check which message GUI_2 sent
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE, $hButton_2
                    GUIDelete($hGUI_2)
            EndSwitch
    EndSwitch

WEnd

Note how we can differentiate between the $GUI_EVENT_CLOSE messages from the 2 windows. :P

All clear? ;)

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
Fran

mmmm... not so clear yet, but I'll get there soon enough.

Another q (I'm keeping you busy)

How do I open windows explorer to a specific path?

example "S:\ContentUpdates\finished"

I've gotten so far as:

Run(explorer.exe)

F

Share this post


Link to post
Share on other sites
Melba23

Fran,

ShellExecute("Your_Folder_Path") :blink:

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
Fran

and I thought "It can't be this easy.." by low and behold, it is!

Thanx dude!

I got some more questions, but I'll post a new thread for the next one.

Once again... Thank you!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.