svkhtn Posted October 10, 2006 Posted October 10, 2006 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!
jvanegmond Posted October 10, 2006 Posted October 10, 2006 That's not possible. Go with the last thing you mentioned. github.com/jvanegmond
randallc Posted October 10, 2006 Posted October 10, 2006 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 ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
svkhtn Posted October 10, 2006 Author Posted October 10, 2006 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.
svkhtn Posted October 10, 2006 Author Posted October 10, 2006 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.
jvanegmond Posted October 10, 2006 Posted October 10, 2006 Try to do a speed test on both ways of doing this: Dim $values[500][500] or your way. github.com/jvanegmond
randallc Posted October 10, 2006 Posted October 10, 2006 (edited) Mai oui naturellement! Mai "pretty" n'est-ce pas? Edited October 10, 2006 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
svkhtn Posted October 10, 2006 Author Posted October 10, 2006 (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 October 10, 2006 by svkhtn
randallc Posted October 11, 2006 Posted October 11, 2006 Hi, the array2D.au3 raised an error.what was the error? I get no error running your script! Best, randall [5th Sept file; Array2D.au3 ; version 4_18 ?] ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
svkhtn Posted October 11, 2006 Author Posted October 11, 2006 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!
randallc Posted October 11, 2006 Posted October 11, 2006 Woops.. OK, updated the zip file; Can you please let me know if it works OK? not sure, in any case, that it really is doing anything special for you anyway, as it still just makes a 2D array .... Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now