Sign in to follow this  
Followers 0
Guest BL@(K-R34P3R

Dim

12 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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?

Share this post


Link to post
Share on other sites

=(, is declaring a variable like:

$music

the same as declaring:

Dim $music

?

Or is Dim totally useless..

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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?

Share this post


Link to post
Share on other sites

Ahh, thanks. =)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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!

Share this post


Link to post
Share on other sites

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)

Share this post


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

Share this post


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

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 :) )

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

Hmm. Nice to know! I will Dim all my variables now, thanks.

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