JunkMaster Posted May 19, 2010 Share 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? Link to comment Share on other sites More sharing options...
Rawox Posted May 19, 2010 Share Posted May 19, 2010 I think it is because of the fact that $A = 1 is actually declaring the $A variable... Link to comment Share on other sites More sharing options...
Tvern Posted May 19, 2010 Share 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. Link to comment Share on other sites More sharing options...
JunkMaster Posted May 19, 2010 Author Share 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. 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