Jump to content

Array2D.au3


randallc
 Share

Recommended Posts

Array2D.zip***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

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

Array2D10.zip

Edited by randallc
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 4 months later...

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
Link to comment
Share on other sites

  • 2 months later...
  • 5 months later...

Hi Randall,

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

Here's an example

#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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 11 months later...

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

Link to comment
Share on other sites

  • 9 months later...

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

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