PPowerHouseK Posted December 18, 2010 Share Posted December 18, 2010 Hello, I am quite new to this language and have tried my best to keep my stupid questions to myself until I have read the documentation and wiki. However it seems as though I have spent a few hrs just trying to find out how to get a simple function to work. I have run the AutoIt 1-2-3 through every tutorial. Perhaps someone here can help shed some light on the matter. I simple want to open an additional GUI when the More button is pressed and close the previous GUI. Here is what I have now: #include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <WindowsConstants.au3> ;begin GUI test GUICreate("Application Complex") $button1 = GUICtrlCreateButton ("More", 10, 10, 150) $cancel = GUICtrlCreateButton ( "Cancel", 355, 370, -1) GUISetState () While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $cancel Then Exitloop If $msg = $button1 Then GUICreate("More GUI") If $msg = $button1 Then Exitloop Wend On that note, is there a way to have it execute a group of commands when the if statement is met, by using brackets of some sort? For example, If $msg = $button1 Then ( GUICreate("this") Beep(500, 1000) ) Thanks in advance! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 18, 2010 Moderators Share Posted December 18, 2010 PPowerHouseK, Here is one way to do what you want: #include <GUIConstantsEx.au3> ;begin GUI test GUICreate("Application Complex", 500, 500, 300, 100) $button1 = GUICtrlCreateButton ("More", 10, 10, 150) $cancel = GUICtrlCreateButton ( "Cancel", 355, 370, -1) GUISetState () While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $cancel Exit Case $button1 ; Delete exisiting GUI GUIDelete("Application Complex") ; Create new GUI GUICreate("More GUI", 300, 300) GUISetState() ; Wait a bit for effect Sleep(1000) ; Leave this loop ExitLoop EndSwitch Wend ; And end up here MsgBox(0, "Well?", "Now what are you going to do?") Note that if you use a Switch structure your Cases are nicely laid out - I find it helps maintain the code more easily. execute a group of commands when the if statement is metYou need to use EndIf like this: If $msg = $button1 Then GUICreate("this") Beep(500, 1000) EndIf You can find out more about it in the Help file under If. It seems that what you have read so far has not helped a lot (but do not get discouraged - we all started there!). Could I recommend this tutorial? It runs you through the basic things nice and simply - might be just what you need. 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...
shanet Posted December 18, 2010 Share Posted December 18, 2010 (edited) Hello, I am quite new to this language and have tried my best to keep my stupid questions to myself until I have read the documentation and wiki. However it seems as though I have spent a few hrs just trying to find out how to get a simple function to work. I have run the AutoIt 1-2-3 through every tutorial. Perhaps someone here can help shed some light on the matter. I simple want to open an additional GUI when the More button is pressed and close the previous GUI. Here is what I have now: #include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <WindowsConstants.au3> ;begin GUI test GUICreate("Application Complex") $button1 = GUICtrlCreateButton ("More", 10, 10, 150) $cancel = GUICtrlCreateButton ( "Cancel", 355, 370, -1) GUISetState () While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $cancel Then Exitloop If $msg = $button1 Then GUICreate("More GUI") If $msg = $button1 Then Exitloop Wend On that note, is there a way to have it execute a group of commands when the if statement is met, by using brackets of some sort? For example, If $msg = $button1 Then ( GUICreate("this") Beep(500, 1000) ) Thanks in advance! To start off I will help you with your if problem. The correct syntax for an if statement is as so: If (condition) Then (instructions) ElseIf (condition) Then (instructions) Else (Instructions) EndIf Therefore, you need only the following: If (condition) Then (instructions) EndIf Your if statement would, therefore, be: expandcollapse popupIf $msg = $button1 Then GUICreate("this") Beep(500, 1000) EndIf [autoit] Now, to move onto your code. The corrected version is below with comments to explain what is happening: [autoit] #include <GUIConstantsEx.au3> ;GUIButton not needed ;WinConstants not needed Opt("MustDeclareVars", 1) ;forces variable decleration - makes for better programming techniques Local $winhandle ;Declaring our variables ;begin GUI test $winhandle = GUICreate("Application Complex") ;When you create a GUI, it returns something called a winhandle, which is a unique ID for the window. ;$winhandle will be given this value. This is used when deleting a window and other functions. $button1 = GUICtrlCreateButton ("More", 10, 10, 150) $cancel = GUICtrlCreateButton ( "Cancel", 355, 370, -1) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $button1 Then GUIDelete($winhandle) ;deletes the old GUI $winhandle = GUICreate("More GUI") ;creates the new GUI and assigns the winhandle. The old GUI winhandle is now not needed, ;so the variable is recycled. GUISetState() EndIf If $msg = $GUI_EVENT_CLOSE or $msg = $cancel Then GUIDelete($winhandle) ;Deletes the GUI ExitLoop EndIf Wend I have left a few things un-declared for you to declare (it will help you learn - not trying to be nasty). As you can see, the contents of the while loop is quite different. I have changed the requirements of exitloop, as you can see there is now an or, and we delete the GUI as this makes for good programming practice if your code then continues as if it does, the GUI will stay. We have got our winhandles which are quite useful. Basically, they are unique ID's of a window. If you wish to see what a winhandle looks like, create a GUI, and messagebox or label the winhandle value. I hope this helps you now, shanet Edited December 18, 2010 by shanet [font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS: %programfiles%/AutoIt3/autoit3.chm Link to comment Share on other sites More sharing options...
PPowerHouseK Posted December 18, 2010 Author Share Posted December 18, 2010 (edited) Thanks you so much, you saved me a LOT of time. I will refrain from asking another remedial question until I have read that tutorial you link from beginning to end. EDIT: I posted the above while shanet was replying. Thank you shanet! I appreciate the time you took to help me learn this new language, your kindness could not be appreciated more! Edited December 18, 2010 by PPowerHouseK 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