Fran Posted July 5, 2010 Share Posted July 5, 2010 (edited) Hi there... I'm pretty new to AutoIt, so please excuse me for my silly questions 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! FranCreateContentUpdate.au3 Edited July 5, 2010 by Fran Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 5, 2010 Moderators Share Posted July 5, 2010 Fran,Welcome to the AutoIt forum. 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. - 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:expandcollapse popup; 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 ;==>_MainI 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 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 Link to comment Share on other sites More sharing options...
Fran Posted July 5, 2010 Author Share Posted July 5, 2010 Wow, thanks! This helps me a great deal. Have a good one! Fran, Welcome to the AutoIt forum. 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. - 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: expandcollapse popup; 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 5, 2010 Moderators Share Posted July 5, 2010 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. 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 Link to comment Share on other sites More sharing options...
Fran Posted July 6, 2010 Author Share Posted July 6, 2010 - 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 6, 2010 Moderators Share Posted July 6, 2010 Fran, like this?Exactly! 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. 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 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 Link to comment Share on other sites More sharing options...
Fran Posted July 6, 2010 Author Share Posted July 6, 2010 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 6, 2010 Moderators Share Posted July 6, 2010 Fran,ShellExecute("Your_Folder_Path") 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 Link to comment Share on other sites More sharing options...
Fran Posted July 6, 2010 Author Share Posted July 6, 2010 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! Link to comment Share on other sites More sharing options...
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