Jump to content



Photo

Array2D.au3


  • Please log in to reply
11 replies to this topic

#1 randallc

randallc

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,902 posts

Posted 20 November 2005 - 12:24 PM

Attached File  Array2D.zip   67.19KB   864 downloads***See the attachment at the bottom for compatability with AutoIt 3.2.10.0 onwards!
Faster Subsort using vbs
Corrected Insert2D;;Updated main udf, not zip, after 127 beta ListView changes
Best, Randall[/color][/b]
Array2D UDF to "include" directory\\3_21 With display of SQLiteDB
AutoIt Link; Beta version here
//** Beta version of AutoIT3 [3.1.1.88..etc] required for Array2D ;
To simplify; You only need the 2 files above in include directory; all the other files are examples of usage
EXAMPLE SCRIPS BELOW=================================================================
Create 2D Arrays from Arrays of 1D Arrays, Display options; with or without zero row or column, with or without Header as zero column or row, click on column to sort, transpose, select lines to text file etc

Show Insert, Delete options too
UDFs to help Array2D usage; various authors; in development or anyone to re-write better?...
_ArrayReplace2DRow(ByRef $avArray, $aRowArray, $nRow = '')
_ArrayReplace2DColumn(ByRef $avArray, $nRow = '')
_ArrayInsert2DColumn(ByRef $avArray, $aRowArray, $nRow = '')
_ArrayDelete2DColumn(ByRef $avArray, $nRow = '')
_Array2DCreateFromArray($ar1_Array_Row1,$Displayindex=1, $ZeroRowAsHeader=0)
_Array2DCreateFirstRow( $aRowArray)
_ArrayInsert2D(ByRef $avArray, $aRowArray, $nRow = "")
_ArrayDelete2D(ByRef $avArray, $nRow = '')
_ArrayToBase1($Array)
_ArrayToBase0($ar_Array)
_StringSplit_B0($s_String,$s_Delimiter="|",$i_Flag="0")
_Array2DTranspose(ByRef $ar_Array)
_Array2DToD(ByRef $ar_Array, $s_Title = "Array contents", $n_Index = 1, $Line = 0, $s_i_Column = 0)
_ArrayViewText($ar2_Array, 'Title', $i_RowStart, $i_ColumnStart, $i_ZeroRowAsHeader,$Transpose, $Width, $Height, $Left, $Right)
$ar2_Array=_Array2DCreate($ar1_Array_Row1,$FirstArrayNumber=1,$LastArrayNumber=4,$ColumnIndex=1, $RowDisplay=0)

=================================================================
Best, randall

Attached Files


Edited by randallc, 06 December 2007 - 10:53 AM.








#2 randallc

randallc

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,902 posts

Posted 20 November 2005 - 12:27 PM

Hi,
Apologies for another UDF which may be superfluous; many comments lately about 2D Arrays being difficult;
I think this makes it easier;
Any feedback welcome; a mixture of other peoples scripts, with modification.
Best, Randall

;Array2DExample4.au3
#include-once
#include <Array2D.au3>
Dim $ar1_Array_Arrays[4]; base 0 for Array of arrays; you can add empty zero row later if needed
;Use either _ArrayCreate or _Stringsplit_B0 or StringSplit to make the 1D Array rows
$ar1_Array_Arrays[0] = _ArrayCreate('animal names', 'aardvark', 'badger','beaver','cat') ; this is always strings starting at zero; base "0"
; OR ; SYNTAX; _StringSplit_B0($s_String,[$s_Delimiter="|",[$i_Flag="0"]]); splits array to base zero (no index at [0])
$ar1_Array_Arrays[1] = _Stringsplit_B0('plant names|Tree|flower|grass|petunia'); else "StringSplit" has strings starting at 1; base "1"
$ar1_Array_Arrays[2] = _Stringsplit_B0('people names|Anne|Joanne|Joan|Cherry')
$ar1_Array_Arrays[3] = _Stringsplit_B0('car names|holden|ford|volkswagon|mitsubishi')

$ar2_Array=_Array2DCreateFromArray($ar1_Array_Arrays )

;OR; .... if you already have named arrays $ar1_Array1,... or whatever, use _ArrayCreate to create your Array of Arrays
;$ar1_Array_Arrays=_ArrayCreate($ar1_Array1,$ar1_Array2,$ar1_Array3,$ar1_Array4,.........)

; Params; $i_RowStart//$i_ColumnStart (zero or 1 for first row//Column to display)
;SYNTAX_ArrayViewText($ar2_Array, 'Title', $i_RowStart, $i_ColumnStart, $i_ZeroRowAsHeader,$Transpose, $Width, $Height, $Left, $Right)
_ArrayViewText($ar2_Array, 'Display', 0,0)



#3 randallc

randallc

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,902 posts

Posted 20 November 2005 - 04:33 PM

Hi,
I have fixed Insert and Delete rows;
Create 2D Arrays from Arrays of 1D Arrays, Display options; Toggle zero row or column, ToggleHeader etc

;Array2DExample6.au3
#include-once
#include <Array2D.au3>
Dim $ar1_Array_Arrays[4]; base 0 for Array of arrays; you can add empty zero row later if needed
$ar1_Array_Arrays[0] = _ArrayCreate('animal names', 'aardvark', 'badger','beaver','cat') ; this is always strings starting at zero; base "0"
$ar1_Array_Arrays[1] = _Stringsplit_B0('plant names|Tree|flower|grass|petunia'); else "StringSplit" has strings starting at 1; base "1"
$ar1_Array_Arrays[2] = _Stringsplit_B0('people names|Anne|Joanne|Joan|Cherry')
$ar1_Array_Arrays[3] = _Stringsplit_B0('car names|holden|ford|volkswagon|mitsubishi')

$ar2_Array=_Array2DCreateFromArray($ar1_Array_Arrays )
;SYNTAX..._ArrayInsert2D(ByRef $avArray, $aRowArray, $nRow = '')
_ArrayInsert2D($ar2_Array, $ar1_Array_Arrays[1])
;SYNTAX..._ArrayDelete2D(ByRef $avArray, $nRow = '')
_ArrayDelete2D($ar2_Array,2)
;_ArrayViewText($ar2_Array, 'Title', $i_RowStart, $i_ColumnStart, $i_ZeroRowAsHeader,$Transpose, $Width, $Height, $Left, $Right)
_ArrayViewText($ar2_Array, 'Display - Click on Column to sort, and Multiple select lines to Text file',0,1,1,1)



#4 randallc

randallc

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,902 posts

Posted 27 November 2005 - 11:23 PM

The Array2.au3 is the Array handling now.
The Array2D.au3 becomes the viewer; it incorporates the "edit in site" from Gary Frost, as well as cloick column sort, toggle zero row on and off, toggle forst row or column as headrer, transpose view rows/ columns.
Best, Randall
PS Added;

_ArrayReplace2DRow(ByRef $avArray, $aRowArray, $nRow = '')
_ArrayReplace2DColumn(ByRef $avArray, $nRow = '')
_ArrayInsert2DColumn(ByRef $avArray, $aRowArray, $nRow = '')
_ArrayDelete2DColumn(ByRef $avArray, $nRow = '')


Edited by randallc, 16 April 2006 - 05:03 AM.


#5 randallc

randallc

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,902 posts

Posted 16 April 2006 - 05:07 AM

Here is new version. [just save in your script directory]
Define rows of 2D array with strings easily, and manipulate.
Example shows a 2D Array sort with subsort by column number and direction. [define as many cols as you want in the "$s_Index" by piped string]
** Now sorts on formatted columns, including numbers, OK
best, randall

Edited by randallc, 16 April 2006 - 05:11 AM.


#6 randallc

randallc

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,902 posts

Posted 16 July 2006 - 01:20 AM

Hi,
Update here makes everything with 2D arrays faster (if large), using vbs helper scrips by scripting object.
Best, randallc

#7 VeeDub

VeeDub

    Polymath

  • Active Members
  • PipPipPipPip
  • 202 posts

Posted 18 December 2006 - 03:04 AM

Hi Randall,

I am trying to use the _ArrayInsert2D function, but it doesn't seem to work as I expected.

Here's an example
Plain Text         
#include <Array2D.au3> ; build array (1D) Dim $avArray[6][2] $avArray[0][0] = "One" $avArray[1][0] = "Two" $avArray[2][0] = "Three" $avArray[3][0] = "Four" $avArray[4][0] = "Five" ; build array (2D) For $i = 0 To 4     $avArray[$i][1] = "Other" Next    ; Display Before for $i = 0 To 5     ConsoleWrite($i & @TAB & $avArray[$i][0] & @TAB & $avArray[$i][1] & @CRLF) Next $Status = _ArrayInsert2D($avArray,3) ConsoleWrite("Status: " & $Status & @TAB & "Error: " & @error & @CRLF) ; Display After for $i = 0 To 5     ConsoleWrite($i & @TAB & $avArray[$i][0] & @TAB & $avArray[$i][1] & @CRLF) Next

and here's the output
>Running:(3.2.1.4):C:\Program Files\AutoIt3\Beta\autoit3.exe "D:\Temp\Outlook\ArrayInsert2D_test.au3"   0   One Other 1   Two Other 2   Three   Other 3   Four    Other 4   Five    Other 5       Status: 0   Error: 0 0   One Other 1   Two Other 2   Three   Other 3   Four    Other 4   Five    Other 5       +>AutoIT3.exe ended.rc:0 >Exit code: 0   Time: 1.647

Am I using the wrong syntax?

Thanks

VW

#8 randallc

randallc

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,902 posts

Posted 18 December 2006 - 05:33 AM

Hi,
Here you go; either of these;

;Array2DExBUG.au3
#include <Array2D.au3>

; build array (1D)
Dim $avArray[5][2]
$avArray[0][0] = "One"
$avArray[1][0] = "Two"
$avArray[2][0] = "Three"
$avArray[3][0] = "Four"
$avArray[4][0] = "Five"

; build array (2D)
For $i = 0 To 4
$avArray[$i][1] = "Other"
Next

; Display Before
for $i = 0 To UBound($avArray)-1
ConsoleWrite($i & @TAB & $avArray[$i][0] & @TAB & $avArray[$i][1] & @CRLF)
Next

;~ $Status = _ArrayInsert2D($avArray,3)
;_ArrayInsert2D($avArray, $aRowArray, $nRow)
dim $aRowArray[2]=["INSERTED","OtherINS"]
$Status =_ArrayInsert2D($avArray, $aRowArray, 3)
ConsoleWrite("Status: " & $Status & @TAB & "Error: " & @error & @CRLF)
$Status =_ArrayInsert2Dst( $avArray, "INSERTED2|OtherINS2", 3)
; Display After
for $i = 0 To UBound($avArray)-1
ConsoleWrite($i & @TAB & $avArray[$i][0] & @TAB & $avArray[$i][1] & @CRLF)
Next

Randall

#9 VeeDub

VeeDub

    Polymath

  • Active Members
  • PipPipPipPip
  • 202 posts

Posted 19 December 2006 - 10:50 AM

That works well.

Thanks

VW

#10 toyotabedzrock

toyotabedzrock

    Seeker

  • Active Members
  • 29 posts

Posted 09 December 2007 - 04:57 AM

If you look at the sig of BugFix in this post, some of his Array2D udfs are actualy in english.

http://www.autoit.de/index.php?page=Thread...21589#post21589

#11 randallc

randallc

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,902 posts

Posted 09 December 2007 - 07:18 AM

If you look at the sig of BugFix in this post, some of his Array2D udfs are actualy in english.

http://www.autoit.de/index.php?page=Thread...21589#post21589

Hi,
True; but why are you pointing this out?
None of them attempt to speed upi array 2D handling uisng vbs as mine do, so there is no comparison.
Best, Randall

#12 taurus905

taurus905

    "Lead, follow, or get out of the way."

  • Active Members
  • PipPipPipPipPipPip
  • 440 posts

Posted 11 September 2008 - 03:24 AM

Hello randallc,
I just wanted to thank you for taking the time to develop such a great UDF and sharing it with the rest of us. I am writing a program which uses IniReadSection and I need to add, delete and sort the two-dimensional array it creates. I had a work-around in mind. But your Array2D.au3 made my life so much easier.
Thanks again for all your work.
taurus905
"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs




4 user(s) are reading this topic

0 members, 4 guests, 0 anonymous users