nitekram Posted February 9, 2015 Share Posted February 9, 2015 I thought that when you declared a variable as Global, and then declared it again as Global - it would overwrite the previous value. But I think it is working more like a Static Variable. And I could be completly wrong too? Here is the code, it runs ever min ie 59 seconds, and it keeps appending EST over and over - I know how to fix it, but really thought that if one was to declare a variable with the same name and scope, that it would set it back to NULL, or at least not keep the current value #include <Date.au3> While 1 If @SEC = 59 Then ; Show current time zone information Global $aOld = _Date_Time_GetTimeZoneInformation() Global $sTimeZone Global $aTimeZone = StringSplit($aOld[2], ' ') Global $iHour = '' Global $sUIP = '' If @HOUR = 0 Then $iHour = 12 & 'AM' ElseIf @HOUR >= 13 Then $iHour = @HOUR - 12 & 'PM' Else $iHour = @HOUR & 'AM' EndIf For $x = 1 To UBound($aTimeZone) - 1 $sTimeZone &= StringLeft($aTimeZone[$x], 1) Next ;_ArrayDisplay($aTimeZone) $sUIP = ' ' & @MON & '.' & @MDAY & '.' & @YEAR & ' | ' & $iHour & ' ' & $sTimeZone MsgBox($MB_OK, 'DATE | HOUR ZONE', 'Send it, clipboarded subject line' & @CRLF & @CRLF _ & $sUIP) ClipPut($sUIP) EndIf WEnd . 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
JohnOne Posted February 9, 2015 Share Posted February 9, 2015 (edited) It does set it back to uninitiated in your case above. The problem there is you do not test it.//I assume it's $sTimeZone as it's the only one declared twice. And as you know declaring variables in a loop is daft. EDIT: Totally misread the code. Edited February 9, 2015 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
water Posted February 9, 2015 Share Posted February 9, 2015 A short test will show you how it works: Global $Test = "Test" ConsoleWrite($Test & @CRLF) Global $Test ConsoleWrite($Test & @CRLF) returns "Test" two times. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
nitekram Posted February 9, 2015 Author Share Posted February 9, 2015 So no bug, but I would think that it would delete whatever value it was - again, I find that I am wrong. Thanks 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
jdelaney Posted February 9, 2015 Share Posted February 9, 2015 (edited) Create a function for the internal If statement, and use LOCAL variables...then they will clear out after each return from the function. Else, specifically set each variable ="" athe the start of the if statement. Edited February 9, 2015 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
TheSaint Posted February 10, 2015 Share Posted February 10, 2015 From what I understand about Global declaration, is that you should only do it once. In fact, you should get an error at compile time if you declare more than once. If you need to reset/destroy a variable, use the Local scope, as suggested. Really though, once you do a Global declaration for a variable, why would you ever need to do so again, when you can set the value to anything, including nothing. If it needs to be destroyed, either use it with Local instead or avoid using a variable altogether ... though I'm sure there is a way to null. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
TheDcoder Posted February 10, 2015 Share Posted February 10, 2015 Thanks for starting this thread EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
water Posted February 10, 2015 Share Posted February 10, 2015 So no bug, but I would think that it would delete whatever value it was - again, I find that I am wrong. Thanks The value of an already declared variable is only changed when you assign a new value to it. Either in the second "Global" statement or in an assignment. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
nitekram Posted February 10, 2015 Author Share Posted February 10, 2015 (edited) Okay, I now see my mistake. Besides declaring the variable as global each time, I thought it was similar to removing the data from an array by redeclaring it with the global key word. I have learned a lot about variables in the last couple of posts, or I am just getting too old to remember, what I already learned. The reason for using the global key word, is that I wanted to keep all the code in one place for testing, and then move it to its own file. Thanks again, for every ones time and help. Edited February 10, 2015 by nitekram 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 10, 2015 Moderators Share Posted February 10, 2015 (edited) There are times when a Global/Dim does change the scope/initializer... actually, only one comes to mind at the moment: #include <Array.au3> Global $gaArr; I'm going to use this in the future, but might not be an array if condition doesn't meet ConsoleWrite(VarGetType($gaArr) & @CRLF) ; not an array _some_func() ConsoleWrite(VarGetType($gaArr) & @CRLF) ; now is an array _ArrayDisplay($gaArr) Func _some_func() If 1 = 1 Then ; condition is met, initialize array Global $gaArr[2] = ["Hello", "There"]; I actually use Dim here as a personal preference so I can track my code and what I'm doing EndIf EndFunc Edit: I use this method when I need to clear/delete an array too, even though it is still probably declared as an array type. Edited February 10, 2015 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
nitekram Posted February 10, 2015 Author Share Posted February 10, 2015 (edited) I was reading a thread, where they did not want to remove the array elements, but only the data, so in your example, you could declare Global $gaArr[2], would remove only that data? Sorry, doing this from my phone. Edited February 10, 2015 by nitekram 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
water Posted February 10, 2015 Share Posted February 10, 2015 Yes, it does. #include <array.au3> Global $gaArr[2] = [1, 2] _ArrayDisplay($gaArr) Global $gaArr[2] _ArrayDisplay($gaArr) returns an empty array the second time. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
nitekram Posted February 10, 2015 Author Share Posted February 10, 2015 (edited) So I think that is where my confusion came in, I thought it would be the same, and remove the value of the data. But I now know better. Edited February 10, 2015 by nitekram 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
JohnOne Posted February 10, 2015 Share Posted February 10, 2015 May I ask, what variable is declared twice in your original code? Either I'm badly blind or none of them are. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
czardas Posted February 10, 2015 Share Posted February 10, 2015 (edited) All the globals (in the first post) are declared over again each time the loop repeats. The declarations really ought to be placed before the loop. Edited February 10, 2015 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
water Posted February 10, 2015 Share Posted February 10, 2015 They get declared multiple times because the Global statements are within the loop. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
JohnOne Posted February 10, 2015 Share Posted February 10, 2015 I see, thought OP meant variable was redeclared each time in loop. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
czardas Posted February 10, 2015 Share Posted February 10, 2015 Declartation occuring in a loop that repeats is always redeclaring after the first run. That's what the 're' part of the word implies. ^^ operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
JohnOne Posted February 10, 2015 Share Posted February 10, 2015 Semantics, I mean it's declared only once in each loop. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
czardas Posted February 10, 2015 Share Posted February 10, 2015 (edited) Ah okay! Each loop? Perhaps using Static is acceptable inside a loop - strange idea though. I believe I would ever do that personally. NOPE ==> Returns an error. Edited February 10, 2015 by czardas operator64 ArrayWorkshop 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