WeMartiansAreFriendly Posted November 28, 2009 Share Posted November 28, 2009 (edited) Here's some examples of how a 'Static' variable will play out (from the new beta)get the beta: http://www.autoitscript.com/autoit3/files/beta/autoitI couldn't wrap my head around how static variables worked until I read this (the example in the help file was confusing) discussionexpandcollapse popup;------------------------------------ ; Example 1 ;------------------------------------ Example1("First value") ;persistent values Example1("A different value") Func Example1($sSet) Static $sValue = $sSet MsgBox(0, 'The value is', $sValue) EndFunc ;------------------------------------ ; Example 2 ;------------------------------------ Global $bFinished = False While $bFinished = False Example2() ;Recursive WEnd Func Example2() Static $iState = 1 Switch $iState Case 1 ConsoleWrite("First call" &@LF) Case 2 ConsoleWrite("Second call" &@LF) Case 3 ConsoleWrite("Third call" &@LF) Case 4 ConsoleWrite("Done" &@LF) $bFinished = True EndSwitch $iState += 1 ;increment the state EndFunc ;------------------------------------ ; Example 3 ;------------------------------------ #include <array.au3> ;----- before $aArray1 = Example3() _ArrayDisplay($aArray1, "Array1: Default") Example3(1, "One") Example3(3, "Three") Example3(5, "Five") Example3(7, "Seven") $aArray2 = Example3(9, "Nine") _ArrayDisplay($aArray2, "Array2: Changed") ;------ after $aArray1 = Example3() _ArrayDisplay($aArray1, "Array1: Changed") Func Example3($iIndex=-1, $vValue="") Static $aArray[10] = [0,1,2,3,4,5,6,7,8,9] If $iIndex > -1 And $iIndex < 10 Then $aArray[$iIndex] = $vValue Return $aArray EndFunc Edited November 28, 2009 by RockemSockem Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
dantay9 Posted November 29, 2009 Share Posted November 29, 2009 Nice example. Covers all the basics. I didn't understand the difference between a static and a constant before, but now I do. 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