Jump to content

Proper format for dimensioned variable?


qwert
 Share

Recommended Posts

I'm using a call that returns an array -- WinGetPos -- for the very first time.

The documentation describes the call this way:

$size = WinGetPos("")

MsgBox(0, "Active window stats (x,y,width,height):", $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3])

What is the proper way to declare the $size variable?

Dim $size [0] [1] [2] [3] doesn't work and the "Dim" documentation doesn't show a clear case.

Thanks in advance.

Link to comment
Share on other sites

If you want to declare a one-dimensional array as in the example, you'd declare each value as such:

Dim $size[0] = 10
Dim $size[1] = 10
Dim $size[2] = 10
Dim $size[3] = 10

The number in [] brackets is the position of the value in the array.

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

If no values are needed, you can define an array based on how many values it will have within it. For example:

Global $size[3]

Would allow you to assign values to $size[0], $size[1], $size[2], and $size[3]. Something like $size[2000], for instance, would allow you to populate up to 2001 values into the array.

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

When you use a function, such as WinGetPos(), the array will usually define itself, without the need of a Dim statement.

However, is cases in which the array is not defined, Dim can be used like this:

Dim $array[4]

This will create a 1-Dimensional array with the following definable values.

$array[0]

$array[1]

$array[2]

$array[3]

Note, there are 4 total elements in the array, however because it is zero-based the last element in the array is referenced by the number 3, despite it being the fourth element.

Hope this helps

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