Jump to content

Declaring Variables


Baraoic
 Share

Recommended Posts

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

@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 by FireFox
Link to comment
Share on other sites

@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

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 bugs
  • helps me ensure the intended scope of the variable is achieved. Local vs. Global
  • It's just good programming. :)
Edited by Zinthose

--- TTFN

Link to comment
Share on other sites

+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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...