Jump to content

Problem with 2 dimensional array


J_Y_C
 Share

Recommended Posts

I am trying to use a 2 dimensional array, but I keep getting the error message:

C:\xxxxxxx\Automation Scripts\PixelPopper.au3 (25) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

The line that it refers to is here:

Global $lineCoors[5][4];Line coordinate data array
$lineCoors[5][1] = ("Line_Top_y_value")
$lineCoors[5][2] = ("Line_Bottom_y_value")
$lineCoors[5][3] = ("Line_Left_x_value")
$lineCoors[5][4] = ("Line_Right_x_value")

Line 25 is $lineCoors[5][1] = ("Line_Top_y_value"), the first one.

Am I declaring the array properly? Can arrays not have string values?

Edited by J_Y_C
Link to comment
Share on other sites

I am trying to use a 2 dimensional array, but I keep getting the error message:

C:\Documents and Settings\jchen.KARAOKEWH\Desktop\Automation Scripts\PixelPopper.au3 (25) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

The line that it refers to is here:

Global $lineCoors[5][4];Line coordinate data array
$lineCoors[5][1] = ("Line_Top_y_value")
$lineCoors[5][2] = ("Line_Bottom_y_value")
$lineCoors[5][3] = ("Line_Left_x_value")
$lineCoors[5][4] = ("Line_Right_x_value")oÝ÷ ظ§{nb³Mú)Þ
+³

This code was working for me since i get the new autoit version

Link to comment
Share on other sites

Arrays in AutoIt are zero based. When you declare them, you are specifying the number of elements, not the index of the last element. So, your highest-numbered index will always be one less than the number you used in your declaration.

In other words, if you declare

Global $myarray[5]

It will have these elements:

$myarray[0]

$myarray[1]

$myarray[2]

$myarray[3]

$myarray[4]

Thus, $myarray[5] will cause AutoIt to complain about dimension ranges exceeded.

BlueBearrOddly enough, this is what I do for fun.
Link to comment
Share on other sites

Ok, this may be a totally stupid question, but if I install the new version, do I need to uninstall the older ones? I am currently using the beta, does the new release have all of the functions that are in the Beta?

Link to comment
Share on other sites

Ah ha! thank you Bluebearr!!

UPDATE

So, I changed it to this:

Global $lineCoors[6][5];Line coordinate data array
$lineCoors[5][1] = ("Line_Top_y_value")
$lineCoors[5][2] = ("Line_Bottom_y_value")
$lineCoors[5][3] = ("Line_Left_x_value")
$lineCoors[5][4] = ("Line_Right_x_value")

got it, thanks...

Edited by J_Y_C
Link to comment
Share on other sites

$i = $i + 1oÝ÷ Øhmz0¬oMúëm­ëjâ²?m»­j|­g­«tߨ¤yêZuا©ÝÆ⫶§Ê«jºÚɽ7êW­¶·¬1ªCÊhý¼¨»¥¯zØ^±©ë,+(ëax%GºÚ"µÍØØ[  ÌÍÚOLHÈHÜÛÝÚ[HPÝ[
    ÌÍÛ]ÓXÜÊH ÉÝÈ  ÌÍÚBÕRPÝÙ]]J  ÌÍØÝÛÛXÒY    ÌÍÛ]ÓXÜÈÉÌÍÚWJB   ÌÍÚHH    ÌÍÚH
ÈBÑ[

Edit: typo

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

  • 2 weeks later...

Arrays in AutoIt are zero based. When you declare them, you are specifying the number of elements, not the index of the last element. So, your highest-numbered index will always be one less than the number you used in your declaration.

In other words, if you declare

Global $myarray[5]

It will have these elements:

$myarray[0]

$myarray[1]

$myarray[2]

$myarray[3]

$myarray[4]

Thus, $myarray[5] will cause AutoIt to complain about dimension ranges exceeded.

We resolved this thread a while back, and I was thinking back and realized that something bluebearr said didn't make sense to me, and needs to be resolved. In this quote, you say that AutoIt is zero based when it comes to arrays (like most languages). However, in the helpfile, it kind of seems to contradict this:

Arrays

An Array is a variable containing series of data elements of the same type and size. Each element in this variable can be accessed by an index number.

An example:

Let's say you want to store these series of characters: "A", "U", "T", "O", "I", "T" and "3".

You could use seven separate variables to do so, but using an Array is more efficient:

$Array[1]="A"

$Array[2]="U"

..etc..

$Array[7]="3"

To access a specific value in an Array, you only have to know the index number:

$MyChar=$Array[3]

This results in $MyChar containing the letter "T" (See also: 'operators').

Here, I am led to believe that the first item in an array is actually 1 !

Was this example done this way just for simplicity?

Link to comment
Share on other sites

We resolved this thread a while back, and I was thinking back and realized that something bluebearr said didn't make sense to me, and needs to be resolved. In this quote, you say that AutoIt is zero based when it comes to arrays (like most languages). However, in the helpfile, it kind of seems to contradict this:

Here, I am led to believe that the first item in an array is actually 1 !

Was this example done this way just for simplicity?

It was...

Some people choose to skip the zero and start from one. However, when doing this, remember that you must declare the array to be 1 more than the biggest element you are going to use.

ie: if the largest element that you are going to use is 5: $array[5]

then you would need to declare the array like so: Dim $array[6]

because although you are not using the 0, its still there and being counted

[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

hi,

And the really confusing language is vbscript, where "ubound" gives the last index number (say the last element number is 5 then vbscript ubound (array) is 5, even though the vbscript array also is numbered 0 to5 , so has 6 elements! ); whereas Autoit gives ubound as the number of elements instead of the last index number!

best, Randall

Edited by randallc
Link to comment
Share on other sites

@randallc,

Would depend on your definition of UBound(). If the upper boundary is outside the limits (i.e subscript error caused), then VBS users would consider that as wierd. Looking at VBS for strengths and weaknesses in the language, I consider arrays are one of the strengths of VBS. Especially the dynamic arrays. But VBS runtime is much larger compared to AutoIt's, so they are more diversified.

It may look strange to you perhaps because you have not had enough time to understand them?

Dim MyArray()

With the above VBS dynamic array declared, you can later ReDim the above to resize and use UBound to give you the upper boundary (not out of bounds). No computation needed.

Link to comment
Share on other sites

Hi, 2MHz,

Yes, tongue in cheek about vbs. I agree;

But making a point that there IS a difference

VBscript===================

dim array(5)

array item 0,1,2,3,4,5 ('5' would be NOT oob)

uboundarray()=5 (but 6 items!)

AutoIt===================

dim array[5]

array item 0,1,2,3,4 ('5' would be oob)

uboundarray()=6 (for same 6 items!)

Best, randall

Link to comment
Share on other sites

Hi, 2MHz,

Yes, tongue in cheek about vbs. I agree;

But making a point that there IS a difference

VBscript===================

dim array(5)

array item 0,1,2,3,4,5 ('5' would be NOT oob)

uboundarray()=5 (but 6 items!)

AutoIt===================

dim array[5]

array item 0,1,2,3,4 ('5' would be oob)

uboundarray()=6 (for same 6 items!)

Best, randall

Comparing vbs arrays to autoit (C/C++) arrays is a mute point

Anyone that knows how c works with arrays will know that what you call zero base index is an offset

Dim $array[5]

$array[0] is 0 offset from 1st position in the array

$array[1] is 1 offset from 1st position in the array

etc...

Therefore

$array[4] is 4 offset from 1st postion hence 5th item in array.

Even tho both access the array the same the declaration has different meaning

vbs - array[5] = 5 is the last index therefore declaring 6 items in the array

c - array[5] = delcaring 5 items in the array

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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