Jump to content

Dim


Guest BL@(K-R34P3R
 Share

Recommended Posts

Guest BL@(K-R34P3R

I do not really understand the Dim command for creating a variable. I know that it declares a variable, possibly more than one on a line, and can pre assign values, but what would you use it for? I see the examples in help file, but I still don't get it.

Link to comment
Share on other sites

It's the opposite of Bright.

(Sorry, couldn't refuse)

It's the same thing as saying "The lightbulb" versus "lightbulb" Dim only means that the compiler picks it up as a variable fatster (though I don't think there is any real speed increase).

Edited by this-is-me
Who else would I be?
Link to comment
Share on other sites

Edited above^ The answer is yes. It also means Dimension, which means that autoit creates the memory space for the variable before the variable is filled. Therefore, the script doesn't have to dynamically add a memory space for the variable to fill it.

Edited by this-is-me
Who else would I be?
Link to comment
Share on other sites

Dim is also required for arrays (you can use Global and Local, but they are essentially specialized Dim-statements).

Edit: Well, except for functions that return an array such as StringSplit :)

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Guest BL@(K-R34P3R

Yes, I am aware of that, but I would only use it for variables anyways. And I have never seen a script where Dim is used Oo. At least not a real script, (besides helpfile)

Link to comment
Share on other sites

The dim statement also acts as internal documentation. Personally, I ALWAYS dim all of my variables at the beginning of every code section and comment on what it is used for. In AutoIt I don't see a real advantage of this because all variables require the '$' prefix. In VB & C (comparitive statements) I used this to show which words are variables and which are user defined functions. Of course you need to follow a naming convention that should be able to distinguish this but it simplifies code maintainability for you and future maintainers.

It comes down to standardizing your code and documentation. I suggest Dimming all variables always.

SUGGESTION: Check out MustDeclareVars Option.

*** Matt @ MPCS

Link to comment
Share on other sites

  • Administrators

The dim statement also acts as internal documentation. Personally, I ALWAYS dim all of my variables at the beginning of every code section and comment on what it is used for. In AutoIt I don't see a real advantage of this because all variables require the '$' prefix. In VB & C (comparitive statements) I used this to show which words are variables and which are user defined functions. Of course you need to follow a naming convention that should be able to distinguish this but it simplifies code maintainability for you and future maintainers.

It comes down to standardizing your code and documentation. I suggest Dimming all variables always.

SUGGESTION: Check out MustDeclareVars Option.

*** Matt @ MPCS

Like Matt says.

Because AutoIt automatically creates a variable when you assign something it is easy to get into trouble in large scripts. For example in one function you might use the variable $thevar and in another you might use $thevari and then you would get confused as your script didn't work as expected. By using the MustDeclareVars option the script will have generated an error and it would be obvious what was wrong (or you could spend weeks trying to find the bug :) )

Link to comment
Share on other sites

I also prefer using Dim because I have worked with VB and VBA. It is easy to miss something if you dont declare.

Also as Jon and Matt said I would also use the MustDeclareVars (I actually didnt know AutoIt had this feature, but now I will be using it).

Enjoy,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

using Dim in a function for calling out global values is where you will find it useful in single dimentioned variables. You could call out each one in the main script, but if you reuse funtions in many scripts and include them, this will save you a lot of time not calling out each global variable from each subscript function you use.

Like many tools, it has many places where it comes in really handy.

AutoIt3, the MACGYVER Pocket Knife for computers.

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...