Sign in to follow this  
Followers 0
svkhtn

Help: 2-dimension array with different sizes for each row?

11 posts in this topic

Hi all,

I tried to search the forum but didn't find any.

I am wondering if I can create a 2-dimension array with different size for each row of that array.

For example:

$a is a two dimension array.

$a[0] has k elements.

$a[1] has n elements.

$a[2] has m elements.

... and so on.

k, n, m are known at the time of declaration but they are different numbers.

Can I do that with autoit?

Or, Is it the only solution that I have to declare the biggest possible size of the array $a and have an 1-dimension array to store the size for each row of $a? In this case there is quite a lot of redundancy (i.e. a lot of empty cells of $a)

Many thanks!

Share this post


Link to post
Share on other sites



Hi,

Does this show a good example?

What do you need?

;nestedarray2.au3
#include"array2d.au3"
dim $m[3],$ar_ar_wd[4]
for $a = 1 to 2
    $m[$a]=$a
next
dim $ab[$a]
for $a = 1 to 2
    $ab[$a]=random(1,$m[$a],1)
next
$ar_ar_wd[0]=StringSplit("a/b/c/d","/")
;~ _ArrayDisplay($ar_ar_wd[1],"$wd[1]")
$ar_ar_wd[1]=StringSplit("p/s","/")
$ar_ar_wd[2]=StringSplit("a/e/i/o/x/y/z/b/c/d","/")
$ar_ar_wd[3]=StringSplit("w/x/y/z/a/e/i/o","/")
$TwoDimArr=_Array2DCreateFromArray($ar_ar_wd)
_ArrayViewText($TwoDimArr, '$TwoDimArr')
MsgBox(0,"","$TwoDimArr[1][$ab[2]="&$TwoDimArr[1][$ab[2]])

if $TwoDimArr[1][$ab[2]]="s" then MsgBox(0,"","YES $TwoDimArr[1][$ab[2]="&$TwoDimArr[1][$ab[2]])
Best, Randall

Share this post


Link to post
Share on other sites

Thanks for your very quick reply!!!

After reading the help file and searching the forum, I also thought it was not possible at the moment.

However, I had an idea as illustrated below:

Dim $a[2]

$s = "00,01,02"
$s1 = "10,11"

$a[0] = StringSplit($s,",")
$a[1] = StringSplit($s1,",")

For $i=0 to UBound($a)-1
    Local $temp = $a[$i]
    For $j=1 to $temp[0]
        MsgBox(0, "Testing array:", $temp[$j])
    Next
Next

In this case, I am able to declare a 2-dimension array with different sizes of each row.

However, manipulating it is not straightforward as using $a[$i][$j] because the syntax checking of AutoIt will raise an error when compiling.

In short, it works but a bit tricky.

Cheers!

That's not possible. Go with the last thing you mentioned.

Share this post


Link to post
Share on other sites

Thanks randallc.

At the time I posted the above message, I didn't see yours. It looks to me it is a good solution.

I will give it a try now. Thanks for your suggestion.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hi randallc,

I tried your array2D.au3, but there is an error. See below:

#include <array2d.au3>
Dim $a[2]

$a[0] = "00,01,02"
$a[1] = "10,11"

$a[0] = StringSplit($a[0],",")
$a[1] = StringSplit($a[1],",")

$a = _Array2DCreateFromArray($a)

For $i=0 to UBound($a)-1
    For $j=1 to $a[$i][0]
        MsgBox(0, "Testing array:", $a[$i][$j])
    Next
Next

Any help please?

Edited by svkhtn

Share this post


Link to post
Share on other sites

I got this:

Array2D.au3 (71) : ==> The requested action with this object has failed.: 
$ar6_Array = $vbs.run ("Array2DCreatefromArrays", $ar1_Array_Arrays, $i_Base) 
$ar6_Array = $vbs.run ("Array2DCreatefromArrays", $ar1_Array_Arrays, $i_Base)^ ERROR
>Exit code: 0   Time: 18.445

Mine is: Array2D.au3 ; version 4_12

I downloaded the zip file from the link in your signature.

Where can I get the version 4_18? 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