CodingMonkey81 Posted September 15, 2016 Share Posted September 15, 2016 (edited) All, My limited AutoIt skills are rusty; I'm attempting to create a dialog box that contains a drop down menu with the option to choose a location. Upon clicking on the "ok" button, the program would launch internet explorer and direct IE to a specific website. Here's what I've got so far: #include <GUIConstantsEx.au3> $hGUI = GUICreate("Select Location", 235, 138, 605, 373) $comboOrder = GUICtrlCreateCombo("", 45, 48, 145, 25) GUICtrlSetData($comboOrder, "Location 1|Location 2|Location 3|Location 4|Location 5|Location 6|Location 7|Location 8|Location 9|Location 10") $btnGo = GUICtrlCreateButton("Ok", 80, 96, 75, 25) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btnGo Switch GUICtrlRead($comboOrder) Case "Location 1" Run("C:\program files\internet explorer.iexplore.exe") Case "Location 2" Case "Location 3" Case "Location 4" Case "Location 5" Case "Location 6" Case "Location 7" Case "Location 8" Case "Location 9" Case "Location 10" EndSwitch EndSwitch WEnd This script has been cobbled together from other snippets of autoit scripts I've found around the forums. The issues I'm facing are that there is no default location that shows up (not major) and also that if I select "Location 1" from the dropdown and click ok, nothing happens. No error, but IE doesn't launch either. (note: I know that I don't have any actions configured for Locations 2-10, I figured I'd do so after I got Location 1 working). Also, after clicking on ok, would the box disappear? Where am I going wrong? Thanks in advance! CM Edited September 15, 2016 by CodingMonkey81 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 15, 2016 Moderators Share Posted September 15, 2016 (edited) @CodingMonkey81 for the "default", just enter something into the GUICtrlCreateCombo line. Other than that, this works fine for me: #include <GUIConstantsEx.au3> $hGUI = GUICreate("Select Location", 235, 138, 605, 373) $comboOrder = GUICtrlCreateCombo("Please select a location", 45, 48, 145, 25) GUICtrlSetData($comboOrder, "Location 1|Location 2|Location 3|Location 4|Location 5|Location 6|Location 7|Location 8|Location 9|Location 10") $btnGo = GUICtrlCreateButton("Ok", 80, 96, 75, 25) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btnGo Switch GUICtrlRead($comboOrder) Case "Location 1" ShellExecute("http://www.google.com") Case "Location 2" Case "Location 3" Case "Location 4" Case "Location 5" Case "Location 6" Case "Location 7" Case "Location 8" Case "Location 9" Case "Location 10" EndSwitch EndSwitch WEnd Your run line is not working because of an invalid path (I think you intended to write "c:\program files (x86)\internet explorer\iexplore.exe") Edited September 15, 2016 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
CodingMonkey81 Posted September 15, 2016 Author Share Posted September 15, 2016 (edited) JLogan, Is there a way to make sure that the URL launches in IE? Not everyone has IE set as their default. That's why I was trying to run IE and then pass the URL along as a variable. Also, how do I get the dialog box to close once I choose a location? Do I just add an "end" at the bottom of the script? Thanks. Edited September 15, 2016 by CodingMonkey81 Changed a word. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 15, 2016 Moderators Share Posted September 15, 2016 Yes, look at the IE functions in the help file. Instead of ShellExecute, which will grab the default browser, use IECreate. As far as the GUI closing, look at ExitLoop in the help file "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
CodingMonkey81 Posted September 16, 2016 Author Share Posted September 16, 2016 Here's what I came up with (which seems to work): expandcollapse popup#include <GUIConstantsEx.au3> #include <IE.au3> $hGUI = GUICreate("Select Location", 235, 138, 605, 373) $comboOrder = GUICtrlCreateCombo("Location 1", 45, 48, 145, 25) GUICtrlSetData($comboOrder, "Location 1|Location 2|Location 3|Location 4|Location 5|Location 6|Location 7|Location 8|Location 9|Location 10") $btnGo = GUICtrlCreateButton("Ok", 80, 96, 75, 25) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btnGo Switch GUICtrlRead($comboOrder) Case "Location 1" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 2" _IECreate ("http://www.msn.com", 0, 1, 0, 0) ExitLoop Case "Location 3" _IECreate ("http://www.yahoo.com", 0, 1, 0, 0) ExitLoop Case "Location 4" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 5" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 6" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 7" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 8" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 9" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 10" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop EndSwitch EndSwitch WEnd The only thing I noticed (which is not a big deal) is that when I click on the dropdown, it shows "Location 1" twice. Thanks again for the pointers. CM Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 16, 2016 Moderators Share Posted September 16, 2016 That is because you are defining it both in your GUICtrlCreateCombo call and your GUICtrlSetData call. Define it only in one. I would suggest doing it in the GUICtrlSetData call, and then setting Location 1 to the default (last parameter). "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
CodingMonkey81 Posted September 16, 2016 Author Share Posted September 16, 2016 6 minutes ago, JLogan3o13 said: That is because you are defining it both in your GUICtrlCreateCombo call and your GUICtrlSetData call. Define it only in one. I would suggest doing it in the GUICtrlSetData call, and then setting Location 1 to the default (last parameter). Got it: expandcollapse popup#include <GUIConstantsEx.au3> #include <IE.au3> $hGUI = GUICreate("Select Location", 235, 138, 605, 373) $comboOrder = GUICtrlCreateCombo("", 45, 48, 145, 25) GUICtrlSetData($comboOrder, "Location 1|Location 2|Location 3|Location 4|Location 5|Location 6|Location 7|Location 8|Location 9|Location 10", "Location 1") $btnGo = GUICtrlCreateButton("Ok", 80, 96, 75, 25) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btnGo Switch GUICtrlRead($comboOrder) Case "Location 1" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 2" _IECreate ("http://www.msn.com", 0, 1, 0, 0) ExitLoop Case "Location 3" _IECreate ("http://www.yahoo.com", 0, 1, 0, 0) ExitLoop Case "Location 4" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 5" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 6" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 7" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 8" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 9" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop Case "Location 10" _IECreate ("http://www.google.com", 0, 1, 0, 0) ExitLoop EndSwitch EndSwitch WEnd (Code for any future time travelers looking at what I changed). Thanks again! Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 16, 2016 Moderators Share Posted September 16, 2016 Just as a suggestion, you could greatly decrease your number of lines by doing something like this: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <IE.au3> Local $iIndex Local $aSites[11] = ["10", "google", "yahoo", "msn", "facebook", "linkedin", "autoitscript", "amazon", "ebay", "woot", "imdb"] $hGUI = GUICreate("Select Location", 235, 138, 605, 373) $comboOrder = GUICtrlCreateCombo("", 45, 48, 145, 25) GUICtrlSetData($comboOrder, "Location 1|Location 2|Location 3|Location 4|Location 5|Location 6|Location 7|Location 8|Location 9|Location 10", "Location 1") $btnGo = GUICtrlCreateButton("Ok", 80, 96, 75, 25, $BS_DEFPUSHBUTTON) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btnGo $iIndex = (StringRight(GUICtrlRead($comboOrder), 1) = 0 ? StringRight(GUICtrlRead($comboOrder), 2) : StringRight(GUICtrlRead($comboOrder), 1)) _IECreate("http://www." & $aSites[$iIndex] & ".com", 0, 1, 0, 0) ExitLoop EndSwitch WEnd You'll also see the $BS_DEFPUSHBUTTON parameter on your button; allows you to just hit enter rather than mouse-clicking the button. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
CodingMonkey81 Posted September 16, 2016 Author Share Posted September 16, 2016 (edited) 22 minutes ago, JLogan3o13 said: Just as a suggestion, you could greatly decrease your number of lines by doing something like this: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <IE.au3> Local $iIndex Local $aSites[11] = ["10", "google", "yahoo", "msn", "facebook", "linkedin", "autoitscript", "amazon", "ebay", "woot", "imdb"] $hGUI = GUICreate("Select Location", 235, 138, 605, 373) $comboOrder = GUICtrlCreateCombo("", 45, 48, 145, 25) GUICtrlSetData($comboOrder, "Location 1|Location 2|Location 3|Location 4|Location 5|Location 6|Location 7|Location 8|Location 9|Location 10", "Location 1") $btnGo = GUICtrlCreateButton("Ok", 80, 96, 75, 25, $BS_DEFPUSHBUTTON) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btnGo $iIndex = (StringRight(GUICtrlRead($comboOrder), 1) = 0 ? StringRight(GUICtrlRead($comboOrder), 2) : StringRight(GUICtrlRead($comboOrder), 1)) _IECreate("http://www." & $aSites[$iIndex] & ".com", 0, 1, 0, 0) ExitLoop EndSwitch WEnd You'll also see the $BS_DEFPUSHBUTTON parameter on your button; allows you to just hit enter rather than mouse-clicking the button. I probably could, but I'd be completely lost in the code and not know how (or where) to update it. Also, I used dummy URLs for this post as the URLs I need to use point at internal server names with data after them (think http://servername.domain.com/access). Not sure how that would skew things. Edit: I think I can figure out (roughly) how it works; I would put the additional data after the ".com" on the (roughly) 20th line, right? And for the server names I would just replace the "google" "Yahoo" with the "server.domain" names, I think. I'll look at the above code and see if I can figure out what you did (and probably maybe someday implement it). Honestly, it's a little... I don't know (how to describe this feeling of coming up with something and having someone show you a better way to do it). But the gist is that it's interesting to see what I wrote and to learn that it wasn't as efficient as it could be (though with my current skill set I'd never be able to come up with the above code. I barely kludged my together as it is.). Don't take this as a negative, because it's not. I am appreciative of the help you've given me. Thanks Edited September 16, 2016 by CodingMonkey81 Better Script Understand Link to comment Share on other sites More sharing options...
spudw2k Posted September 16, 2016 Share Posted September 16, 2016 I'd think it'd be better to just spell out the URLs...unless you know for a fact that each one in the future will always start with www. and end with .com. Just my advice...but if the use case doesn't fit...don't wear it. Don't get me wrong, I'm all for code simplification and modularity, but I think there's more robust ways to do so. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
CodingMonkey81 Posted September 16, 2016 Author Share Posted September 16, 2016 14 minutes ago, spudw2k said: I'd think it'd be better to just spell out the URLs...unless you know for a fact that each one in the future will always start with www. and end with .com. Just my advice...but if the use case doesn't fit...don't wear it. Don't get me wrong, I'm all for code simplification and modularity, but I think there's more robust ways to do so. In this case, the URLs I'm using are internal servers so they're not going to change very often. But that's good to keep in mind. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 16, 2016 Moderators Share Posted September 16, 2016 59 minutes ago, CodingMonkey81 said: the gist is that it's interesting to see what I wrote and to learn that it wasn't as efficient as it could be (though with my current skill set I'd never be able to come up with the above code. I barely kludged my together as it is.) Understand, there is absolutely nothing wrong with your code the way you have it; it is solid and works. You will find, as you continue using AutoIt, that there are often many multiple ways to tackle a problem. Forum members will often offer up alternatives simply as a "You could always do it this way, too" suggestion; often those suggestions may lead to something you've never considered, or you may find an amalgam of several suggestions gives you the code that works best for your situation spudw2k and Xandy 2 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
CodingMonkey81 Posted September 16, 2016 Author Share Posted September 16, 2016 1 minute ago, JLogan3o13 said: Understand, there is absolutely nothing wrong with your code the way you have it; it is solid and works. You will find, as you continue using AutoIt, that there are often many multiple ways to tackle a problem. Forum members will often offer up alternatives simply as a "You could always do it this way, too" suggestion; often those suggestions may lead to something you've never considered, or you may find an amalgam of several suggestions gives you the code that works best for your situation Thanks again. Seriously. I know I keep thanking you, but it's nice to have someone (even if only once) foster growth in learning something new and taking the time out to explain things. 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