Sign in to follow this  
Followers 0
Baraoic

Declaring Variables

6 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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

--- TTFN

Share this post


Link to post
Share on other sites

Good programming practice dictates declaring variables in the proper scope, using proper declaration techniques.

Share this post


Link to post
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]

Share this post


Link to post
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
Sign in to follow this  
Followers 0