butterfly Posted April 14, 2014 Share Posted April 14, 2014 Hello FellowForumers I have some questions about this subject and Although I have researched about i have some problems let it sink in proper Although i have basic understanding of Global and Local I Still have questions to be absolute sure: #include <Array.au3> Global $TSAB[20] While 1 trading() If $TSAB[19] = True Then MsgBox(0,"","Thank you AutoIT Forum ^^ ") ;~ If $TSAB[19] = True then Exit WEnd func trading() $TSAB[19] = "" $TSAB[7] = "" while 1 _ArrayDisplay($TSAB) $TSAB[7] = "done" _ArrayDisplay($TSAB) If $TSAB[7] = "Done" Then $TSAB = ClientDoneCommand() _ArrayDisplay($TSAB) If $TSAB[19] = True then Return $TSAB WEnd EndFunc func ClientDoneCommand() $TSAB[19] = True Return $TSAB EndFunc My own example Above gives to me Decent understanding that Global can be called anywhere in the program and that the global variable is sent and called towards other functions and loops as it was just before it got sent or returned is there anything I have to keep in mind to Prevent any big mess? Am I something missing about this or has anyone some advice? I will use this global as the soul of my program and store information on where it has been and been and what functions it has visit and what it has been doing etc Here I move to Local $var So I got the same script and added some Local var: #include <Array.au3> Global $TSAB[20] local $hugs = "" While 1 ConsoleWrite($hugs & "0" & @LF) ;Added line $hugs = trading() If $TSAB[19] = True Then MsgBox(0,"","Thank you AutoIT Forum ^^ ") ;~ If $TSAB[19] = True then Exit ConsoleWrite($hugs & "1" & @LF) ;Added line WEnd func trading() $TSAB[19] = "" $TSAB[7] = "" local $hugs = "yes" while 1 ConsoleWrite($hugs & "2" & @LF) ;Added line _ArrayDisplay($TSAB) $TSAB[7] = "done" _ArrayDisplay($TSAB) If $TSAB[7] = "Done" Then $TSAB = ClientDoneCommand($hugs) _ArrayDisplay($TSAB) ConsoleWrite($hugs & "4" & @LF) ;Added line If $TSAB[19] = True then Return $TSAB WEnd EndFunc func ClientDoneCommand($hugs) $TSAB[19] = True ConsoleWrite($hugs & "3" & @LF) ;Added line $hugs = "Maybe" Return $TSAB EndFunc Here I added a few console writes and numbered them the consolewrite output is 0 yes2 yes3 yes4 1 repeat So the following things I see in my blurry mind as are as follow at the very start I need to declare Local $hugs = "" else ; ConsoleWrite($hugs & "0" & @LF) ;Added line will have variable used before declaration (meaning nothing has been stored ever which I understand) Now here comes an interesting part to me, about: $hugs = trading() If $TSAB[19] = True Then MsgBox(0,"","Thank you AutoIT Forum ^^ ") ;~ If $TSAB[19] = True then Exit ConsoleWrite($hugs & "1" & @LF) ;Added line here Happens nothing , not even a error (which I expected) I do not get a consolewrite: 0 it does not output anything I understand that the functions has not returned the variable of local $hugs = "yes" or $hugs = "Maybe" But I expected an error, why no error? What Happens with the at line 33 $hugs = "Maybe" does it get lost? deleted (from the memory ) at the end of the function? @ line 17? local $hugs = "yes" Would it be wise to write there local $hugs = "yes" or is $hugs = "yes" Good enough , does it really matter with managing anything? and as last I also understand if I would change that at line 26 that it is not needed the write return $TSAB but just return would be good enough? because $TSAB is in every function / If / while for next loop avaiable and it will carry over the information stored inside of it? if i would change it into Return $hugs then ConsoleWrite($hugs & "1" & @LF) will give me yes1 and even at the very start of the while loop ConsoleWrite($hugs & "0" & @LF) will give me yes0 and it was previous just 0 so it seems anything wrong here? so it seems the local does not get lost at the end of the while loop then my final questions about for / next For $z = 0 to 9 For $x = 0 to 9 For $y = 0 to 9 ConsoleWrite($z & $x & $y & @LF) next next next if $z = 9 Then MsgBox(0,"","1000 ^^ ") if $x = 9 Then MsgBox(0,"","x = 9 ^^ ") if $y = 9 Then MsgBox(0,"","y = 9 ^^ ") the Variable $z , $x and $y are they only used in the for next loop or can they be used outside of it? my msgboxs do not work here after the next so i guess they end right away in the for next loop any tips or suggestions are welcome if i am saying anything wrong or retarded here Cheers Butterfly Link to comment Share on other sites More sharing options...
water Posted April 14, 2014 Share Posted April 14, 2014 tl;dr All you need to know about Global/Local is described in the Help file or in the Wiki. My UDFs and Tutorials: Spoiler 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 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