xuzo Posted July 8, 2012 Posted July 8, 2012 This is pretty hard to explain but I'll try to make it as clear as possilbe! When doing a loop, the code will go back to the first line, how to make it go back to not the beginnig but further down in the script? For $i = 1 To 2 Step 1 ;step one code line 1 MsgBox(0, "Title", "This is the line 2 of the code") ;step two code line 3 MsgBox(0, "Title", "This is the line 4 of the code") ;step three code line 5 MsgBox(0, "Title", "This is the line 6 of the code") ;step 4 code line 7 MsgBox(0, "Title", "This is the line 8 of the code") ;what could I use to return to line of code 4 instead of 1? Next I can do this is Vista Task studio but wondering if AutoIT can do it also? Here is the help file from the other software, it's also based on Visual Basics I think: Quote GOTO Label Jumps to a label. The label can come before or after this command (anywhere in the script). User Variables (such as "%label") may be used as the destination. Labels that are skipped will not be used as a destination. You can jump directly to a hard-coded step (without defining a Label) by using the {STEP1}, {STEP2}, etc. system variables. These system variables are only accessed by the Goto Label action. If you move steps around, the Goto Label will still jump to the same step. "Goto Label" serves the same purpose as a GOTO programming statement - it immediately goes to the indicated step. If the specified label does not exist, a warning is displayed and execution stops.
water Posted July 8, 2012 Posted July 8, 2012 AutoIt has no "Goto". If you want to repeat only some code in the loop set a flag and execute the code depending on the flag. My UDFs and Tutorials: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
czardas Posted July 8, 2012 Posted July 8, 2012 (edited) There are different methods. The code below shows two possibie methods. For $i = 0 To 1 ; Loops twice MsgBox(0, "Title", "This is the line 1") For $j = 0 To 1 ; Nested loop method MsgBox(0, "Title", "This is the line 2") MsgBox(0, "Title", "This is the line 3") Next MsgBox(0, "Title", "This is the line 4") _Lines5and6() ; Call a function method MsgBox(0, "Title", "This is the line 7") Next Func _Lines5and6() Local $iCount = 0 ; counter Do MsgBox(0, "Title", "This is the line 5") MsgBox(0, "Title", "This is the line 6") $iCount += 1 ; Increment the counter Until $iCount = 2 EndFunc Edited July 8, 2012 by czardas operator64 ArrayWorkshop
xuzo Posted July 9, 2012 Author Posted July 9, 2012 (edited) Thanks guys, I've simplified the code above so I can understand better like this: MsgBox(0, "Title", "1") _flagY();GOTO line 10 of code MsgBox(0, "Title", "2") _flagX() ;GOTO line 7 of code MsgBox(0, "Title", "3") Func _flagX();Set Flag to line 7 MsgBox(0, "Title", "4") EndFunc ;==>_flagX Func _flagY();Set Flag to line 10 MsgBox(0, "Title", "5") EndFunc ;==>_flagY Althought this works fine, seems a little complicated... Water said: Quote set a flag and execute the code depending on the flag I've searched for "flag" in help file but nothing there, any clear and very simple example of working with flags? Or maybe the way I did it up there is already the easiest way? Thanks Edited July 9, 2012 by xuzo
water Posted July 9, 2012 Posted July 9, 2012 A "flag" is a simple variable. The content tells you what to do. You decide what the content and the meaning of the content is. $iFlag = 1 While 1 If $iFlag = 1 Then ; Your code $iFlag = $iFlag +1 EndIf If $iFlag = 2 Then ; Your code ExitLoop EndIf WEndRuns the loop 2 times executing different code and then exits (I know it can be done much easiert - but it's just to show how "flags" work). My UDFs and Tutorials: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
xuzo Posted July 9, 2012 Author Posted July 9, 2012 (edited) Hi Water, Thanks for the tip, I've interpretated this way: $myvariable = 1 While 1 If $myvariable = 1 Then MsgBox(0, "title", "The variable equals 1") EndIf $myvariable = $myvariable + 1 If $myvariable = 2 Then MsgBox(0, "title", "The variable equals 2") ExitLoop EndIf WEnd so basically $iflag can be anything? Additionally, why are there often some "i"s right after the dollar sign? Is that a convention? Edited July 9, 2012 by xuzo
water Posted July 9, 2012 Posted July 9, 2012 Yes, The i and others are a convention mostly used in UDFs to show you the data type of the content. i means integer, s is for strings etc.Details can be found here. My UDFs and Tutorials: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted July 9, 2012 Posted July 9, 2012 My UDFs and Tutorials: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
xuzo Posted July 9, 2012 Author Posted July 9, 2012 Wow! Thanks for the link Will look at that list over a few beers in my regular bar in Thailand a little later, will save it for my Kindle!
czardas Posted July 9, 2012 Posted July 9, 2012 (edited) LOL I deleted my last post because water got there first. xuzo, you need to stop thinking in terms of GoTo. The point is that functions replaced GoTo, at least in AutoIt. Here's another idea. You can step backwards in a loop, but be careful you don't end up in an infinite loop. $iFlag = 0 For $i = 1 To 4 MsgBox(0, "Title", "Index = " & $i) If $i = 3 And $iFlag < 4 Then $i -= 2 $iFlag += 1 EndIf Next Edited July 9, 2012 by czardas operator64 ArrayWorkshop
water Posted July 9, 2012 Posted July 9, 2012 On 7/9/2012 at 6:48 AM, 'xuzo said: Will look at that list over a few beers in my regular bar in Thailand a little later ...Thailand, beer, bar? I will come over and explain everything in detail over a few beers My UDFs and Tutorials: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
xuzo Posted July 12, 2012 Author Posted July 12, 2012 Hi Water, Yes that would be cool indeed, actually if anybody from this forum ever comes to Pattaya send me a PM! Cheers!
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