Baraoic Posted December 23, 2008 Share Posted December 23, 2008 So I have been wondering if I am missing something. I have noticed that there is an option for must declare variables, but by default its off. Then why is it that you can still get errors if you don't declare them? Then why doesn't autoit just auto declare all variables that aren't previously declared? Also I have read that its good to declare all of them why is that? Link to comment Share on other sites More sharing options...
FireFox Posted December 23, 2008 Share Posted December 23, 2008 (edited) @Onichan Its good to declare variables because a variable is never nothing (I dont mean ""), so you have to declare it to use it and you can specify variable to a thing : $variable = "code";here the variable is code $variable = GuiCtrlCreateLabel;here the variable is label so with this variable you can edit it I hope i've help you Edited December 23, 2008 by FireFox Link to comment Share on other sites More sharing options...
Baraoic Posted December 23, 2008 Author Share Posted December 23, 2008 @Onichan Its good to declare variables because a variable is never nothing (I dont mean ""), so you have to declare it to use it and you can specify variable to a thing : $variable = "code";here the variable is code $variable = GuiCtrlCreateLabel;here the variable is label so with this variable you can edit it I hope i've help you Thanks for the response, but I know you can declare a variable to anything, but the thing is why isn't it by default blank. I think it would prevent a lot of errors, at least for me, because I use "$var &= 5" or similar quite a bit. Then whats the purpose of the option must declare variable then if you have to declare them anyways? Link to comment Share on other sites More sharing options...
Zinthose Posted December 23, 2008 Share Posted December 23, 2008 (edited) Thanks for the response, but I know you can declare a variable to anything, but the thing is why isn't it by default blank. I think it would prevent a lot of errors, at least for me, because I use "$var &= 5" or similar quite a bit. Then whats the purpose of the option must declare variable then if you have to declare them anyways?The primary purpose, for me anyway, is debugging / scope checking..removes the chance for misspelled variables causing bugshelps me ensure the intended scope of the variable is achieved. Local vs. GlobalIt's just good programming. Edited December 23, 2008 by Zinthose --- TTFN Link to comment Share on other sites More sharing options...
Richard Robertson Posted December 23, 2008 Share Posted December 23, 2008 Good programming practice dictates declaring variables in the proper scope, using proper declaration techniques. Link to comment Share on other sites More sharing options...
bo8ster Posted December 23, 2008 Share Posted December 23, 2008 +1 on that. Things like this and VB that let you get away without declaring is mad because it just cost you more time in the end chasing down variables because of spelling, scope and a tone of other reasons. Do AutoItSetOption("MustDeclareVars", 1) and be done with it - u'll be happy you did. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] 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