JunkMaster 0 Posted May 19, 2010 I am just starting to write my first script in AutoIt. I was looking through the examples in the helpfile and found the example for _GUICtrlTreeView_ExpandedOnce.au3. In this example they use $x and $y, but do not declare them. The script includes the directive: Opt('MustDeclareVars',1). My understanding is this means all variables must be defined before they are used. I ran a quick test and found that: Opt('MustDeclareVars', 1) $A = 1 msgbox(1,"Test $A", "$A = " & $A) generates a "Variable used without being declared." error. But this does NOT generate an error: Opt('MustDeclareVars', 1) for $A = 1 to 4 msgbox(1,"Test $A", "$A = " & $A) Next What am I missing? Share this post Link to post Share on other sites
Rawox 0 Posted May 19, 2010 I think it is because of the fact that $A = 1 is actually declaring the $A variable... Share this post Link to post Share on other sites
Tvern 11 Posted May 19, 2010 Your first example won't error if you use "Local $A = 1", but I think you realise that.Ftr the second example read the helpfile on Keyword For...To...Step...Next:The Variable will be created automatically with a LOCAL scope, even when MustDeclareVars is on. Share this post Link to post Share on other sites
JunkMaster 0 Posted May 19, 2010 Your first example won't error if you use "Local $A = 1", but I think you realise that.Ftr the second example read the helpfile on Keyword For...To...Step...Next:Thank's Tvern. That is the missing info. I never thought to look at the definition of the For loop. Share this post Link to post Share on other sites