Jump to content

Bug With Multidimensional Array Initialization?


Recommended Posts

Bug or not?

To me this should work

Global $Button_Info[1][4]=[[0], [-999,"",0x000000,0xd3d3d3]]

but it errors out

C:\Documents and Settings\FROST-GA\My Documents\AutoIt\test4.au3 (2) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Global $Button_Info[1][4]=[[0], [-999,"",0x000000,0xd3d3d3]]

Global $Button_Info[1][4]=[[0], [^ ERROR

This does work, but I don't need the extra slot in the array

Global $Button_Info[2][4]=[[0], [-999,"",0x000000,0xd3d3d3]]

this also works, just for testing

Global $Button_Info[2][4]=[[0,0], [-999,"",0x000000,0xd3d3d3]]

Let's take this a little bit further

The following works as I would expect it to.

Global $Button_Info[1][4]
$Button_Info[0][0] = -999
$Button_Info[0][1] = ""
$Button_Info[0][2] = "0x000000"
$Button_Info[0][3] = "0xd3d3d3"
For $x = 0 To 3
    ConsoleWrite($Button_Info[0][$x] & @LF)
Next

Now if the array is initialized when it is declared, then either I'm doing something wrong or there is a bug

I would expect the following to be the same as above but it isn't

Global $Button_Info[2][4]=[[0], [-999,"test","0x000000","0xd3d3d3"]]
For $x = 0 To 3
    ConsoleWrite($Button_Info[0][$x] & @LF)
Next

this is what works to get the 4 items

Global $Button_Info[2][4]=[[-999,"test","0x000000","0xd3d3d3"],[0]]
For $x = 0 To 3
    ConsoleWrite($Button_Info[0][$x] & @LF)
Next

Gary

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

  • Moderators

bump - hope it's not me

Well I'd say if you say it's a bug, it's more than likely one! Perhaps Nutster or Jdeb could shed more light.

I would assume that the first example should work, and I have ran into this issue before myself. And just passed it off as bad coding on my part.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Developers

bump - hope it's not me

My vote is BUG..

this doesn't give an error:

Global $Button_Info[2][1]=[[0],[0]]

This does:

Global $Button_Info[1][1]=[[0],[0]]

test.au3 (1) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Global $Button_Info[1][1]=[[0],[0]]

Global $Button_Info[1][1]=[[0],[^ ERROR

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

My vote is BUG..

this doesn't give an error:

Global $Button_Info[2][1]=[[0],[0]]

This does:

Global $Button_Info[1][1]=[[0],[0]]
What do you think about the initialization when declaring as I have shown above post? 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

...

Global $Button_Info[1][4]=[[0], [-999,"",0x000000,0xd3d3d3]]

...

Global $Button_Info[2][4]=[[0], [-999,"",0x000000,0xd3d3d3]]

...

Global $Button_Info[2][4]=[[0,0], [-999,"",0x000000,0xd3d3d3]]

...

...

Global $Button_Info[2][1]=[[0],[0]]

...

Global $Button_Info[1][1]=[[0],[0]]

...

Ok, I think I've figured it out... You don't have to specify the first dimension when declaring an array inline:

This code should replace gafrost's first example for correctness:

Global $Button_Info[1][4]=[[-999,"",0x000000,0xd3d3d3]]

The red brackets indicate the first dimension, the brackets in blue indicate the second dimension. Take this example:

#include <ArrayToDisplayString.au3>
Dim $Grid[4][4]=[["Paul", "Jim", "Richard", "Louis"],[1,2,3,4],[-999,"",0x000000,0xd3d3d3],["test1",1,"test2",2]]
MsgBox(0,"",_ArrayToDisplayString($Grid))

_ArrayToDisplayString.au3 is attached.

Dim $Grid[4][4]=[["Paul", "Jim", "Richard", "Louis"],[1,2,3,4],[-999,"",0x000000,0xd3d3d3],["test1",1,"test2",2]]

Using the same coloring scheme, the very first and very last brackets (red) indicate it is describing the first dimension, and blue brackets indicate a second dimension. Last example, three-dimensional declaration.

#include <ArrayToDisplayString.au3>
Dim $Grid[2][2][2]=[[["Paul", "Jim"],[1,2]],[["test1","test2"],["last","one"]]]
MsgBox(0,"",_ArrayToDisplayString($Grid))

Dim $Grid[2][2][2]=[[["Paul", "Jim"],[1,2]],[["test1","test2"],["last","one"]]]

red = 1st Dimension

blue = 2nd Dimension

green = 3rd Dimension

ArrayToDisplayString.au3

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

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