bootybay Posted April 16, 2017 Share Posted April 16, 2017 I'm having problems grasping some concepts. I'll show you what I want to try and if it makes sense to you. Func Stat() Static $Region = StringSplit(StringStripWS (IniRead("win7.ini", "Update", "Complete", "600, 500, 620, 520, 0x00FF00"), 8), ",", 2) PixelSearch($Region[0], $Region[1], $Region[2], $Region[3], $Region[4]) If Not @error Then Return True EndFunc Func Test() While True If Stat() = True Then ExitLoop Sleep(5000) WEnd MsgBox(0, "Update", "complete!") EndFunc So Stat() gets called over and over again. I want to read the INI only once and from then on keep using the $Region values. I don't want to declare a global or pass the array as ByRef into stat. Basically I want to IniRead the values while $Region is empty and then once it got its values not do it anymore. I want to keep it contained in Stat. But I don't know how to do this. Please let me know if I need to clarify this a little more. Link to comment Share on other sites More sharing options...
czardas Posted April 16, 2017 Share Posted April 16, 2017 So what is the problem you are experiencing? operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
czardas Posted April 16, 2017 Share Posted April 16, 2017 (edited) 24 minutes ago, bootybay said: I want to read the INI only once and from then on keep using the $Region values. Your implementation of Static looks okay to me. Whatever the problem is, it's not due to a misunderstanding of Static. Edited April 16, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Developers Jos Posted April 16, 2017 Developers Share Posted April 16, 2017 (edited) 32 minutes ago, bootybay said: So Stat() gets called over and over again. I want to read the INI only once and from then on keep using the $Region values. I don't want to declare a global or pass the array as ByRef into stat. To me these 2 lines contradict each other: When you want a variable to be set ones, it will have to be global as any local variable only exists till the FUNC ends. Jos Edited April 16, 2017 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 16, 2017 Moderators Share Posted April 16, 2017 bootybay, Your code looks fine to me - but I would suggest using "Local Static" to declare the array just to remind yourself that it is not available outside the function. 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...
czardas Posted April 16, 2017 Share Posted April 16, 2017 (edited) The static variable here ought to be kept in memory but not available to other functions. That's how it works for me anyway. And yeah @Melba23 is right about adding Local, even though it should already work. Edited April 16, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Developers Jos Posted April 16, 2017 Developers Share Posted April 16, 2017 (edited) 6 minutes ago, czardas said: The static variable here ought to be kept in memory but not available to other functions. That's how it works for me anyway. Are you sure? Try this little snippet which shows it has to be defined each time or am I missing something?: For $x = 1 To 5 Test() Next Func Test() If IsDeclared("testvar") Then ConsoleWrite("Already defined" & @CRLF) Else ConsoleWrite("Initialise $Testvar" & @CRLF) Static $testvar = "123" EndIf If IsDeclared("testvar") Then ConsoleWrite("testvar defined" & @CRLF & @CRLF) EndIf EndFunc ;==>Test Edited April 16, 2017 by Jos czardas 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 16, 2017 Moderators Share Posted April 16, 2017 Jos, To show it works: Global $iGlobal_Count = 0 For $i = 1 To 5 $iGlobal_Count += 1 _Test() Next Func _Test() Local Static $iStatic_Count = $iGlobal_Count ; Should only be executed once and retain the value 1 on subsequent calls ConsoleWrite($iGlobal_Count & " - " & $iStatic_Count & @CRLF) EndFunc 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...
czardas Posted April 16, 2017 Share Posted April 16, 2017 (edited) @Jos Indeed, I see where you are coming from with that snippet. My wording is off. On redeclaration the variable is initialized with the previous value which is held somewhere in memory. Is that any better? Edited April 16, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Developers Jos Posted April 16, 2017 Developers Share Posted April 16, 2017 Ah.. that is how it works. That is confusion for my brain. It doesn't actually exists but when you re-declare it, it will take the value of the initial declaration. Guess it is clear I have never used it as yet and probably won't in the future. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
czardas Posted April 16, 2017 Share Posted April 16, 2017 (edited) I've only used it a couple of times myself. It's definately worth having, even if it's not entirely necessary. Actually, it takes the last value prior to exiting the function (on the previous call); not the initial value (which may have been modified). Edited April 16, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
bootybay Posted April 16, 2017 Author Share Posted April 16, 2017 Thank you all for all the super fast responses. Your example clarified this for me @Melba23. Link to comment Share on other sites More sharing options...
czardas Posted April 16, 2017 Share Posted April 16, 2017 (edited) One more example: demonstrating further application (the result of modifying a static variable). Global Const $iInit = 11 For $x = 11 To 15 Test() Next Func Test() Local Static $iCount = $iInit ConsoleWrite($iCount & @LF) $iCount += 1 EndFunc ;==>Test Edited April 16, 2017 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