Array Extract Column/ Row 0

Go to solution Solved by Melba23,

Recommended Posts

I am trying to get column 0 from A 2D array.

In the below example,  (adapted from Autoit Example Script for _ArrayExtract)

The first ArrayExtract works as expected and returns only column 1 | Start Column  = 1 End column = 1

The Second ArrayExtract returns data from all columns. | Start Column  = 0 End column = 0

The Third ArrayExtract works as expected and returns only Row 1 . | Start Row = 1 End Row = 1

The Fourth ArrayExtract returns data from all Rows. | Start Row = 0 End Row = 0

If start = 1 end = 1 returns column 1 And/ row 1  respectively why does start = 0 end = 0 return all rows/columns.

What is the correct variables to use to extract only row 0 OR column 0?

Thank You,

Shane

Edit: Added work around function for anyone who needs it, description near bottom of post.

```#include <Array.au3>

Local \$aArray[4][4]
For \$i = 0 To 3
For \$j = 0 To 3
\$aArray[\$i][\$j] = \$i & \$j
Next
Next
_ArrayDisplay(\$aArray, "Original")

Local \$aExtract = _ArrayExtract(\$aArray, 0, 3, 1, 1) ; works as expected
_ArrayDisplay(\$aExtract, "Row 0-3 column 1")

Local \$aExtract = _ArrayExtract(\$aArray, 0, 3, 0, 0) ; irregular results
_ArrayDisplay(\$aExtract, "Row 0-3 column 0")

Local \$aExtract = _ArrayExtract(\$aArray, 1, 1, 1, 3); works as expected
_ArrayDisplay(\$aExtract, "Row 1 column 1 - 3")

Local \$aExtract = _ArrayExtract(\$aArray, 0, 0, 1, 3) ; irregular results
_ArrayDisplay(\$aExtract, "Row 0 column 1 - 3")```

ArrayExtract.au3

Edited by Shane0000
Share on other sites

Shane0000,

This is how I would do it...

```#include <Array.au3>

Local \$aArray[4][4]
For \$i = 0 To 3
For \$j = 0 To 3
\$aArray[\$i][\$j] = \$i & \$j
Next
Next
_ArrayDisplay(\$aArray, "Original")

; if you want the value at the offset
ConsoleWrite('value at row0/column0 = ' & \$aArray[0][0] & @CRLF)

; if you want all of column 0
for \$1 = 0 to ubound(\$aArray) - 1
ConsoleWrite(\$aArray[\$1][0] & @CRLF)
next```

I could not get _arrayextract to work after a cursory attempt.  The doc for this function appars to be cloned from _arraydelete as \$vrange is referenced in the REMARKS but does not appear in the function prototype or parameter definitions and appears to be in error.  I believe that most array UDF's reserve row 0 col 0 for a count (don't really know as I rarely use them except _arraydisplay).

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share on other sites

Yeah writing code to do it would work but it seems like the function should work.

IMO a -1 would be better variable for all data as not all arrays are created with an array count in column 0.

Anywho what If I wanted all the array counts for that matter? 0,0 still would give erroneous results.

Also you cannot get row 0 from this function :/

Edited by Shane0000
Share on other sites
Anywho what If I wanted all the array counts for that matter? 0,0 still would give erroneous results.

What does this mean?  There is only 1 array.

Also you cannot get row 0 from this function :/

I could not get it either...

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share on other sites

i was referring to your post about 0/0 holding a count. usually a created array does have the count in column 0. , a n array from  _Array Concatenate may have all counts in column 0 but thats off topic

My array is from a defined array that values gets data assigned to it so row 0 and column 0 hold data that I would like to quickly and easily access as this Function describes its self to do :

'Extracts an array from the specified element(s) of a 1D or 2D array'

I simply would like the ability to specify column 0 or Row 0

Share on other sites

I agree with you.  I am trying to figure out how/if a trac ticket should be opened, at least for doc clarification/correction.

edit: One thing you might consider.  It is simple code, create your own function/UDF.

edit2: spelling...this KB is SHIT

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share on other sites

Yeah I forget where / how the ticket is / works, I was just hoping this would get stumbled upon and brought to attention.

Thank you

Share on other sites

Here is my workaround:

This will extract data from 1d and 2d arrays and will give you access to row 0 and column 0

This works with the same syntax of _ArrayExtract

ArrayExtract(Source array, Start Row, End Row, (optional) Start Column, (optional) End Column)

Example Script attached

```Func ArrayExtract(ByRef \$aArray,\$iRstart, \$iRend, \$iCstart = 0, \$iCend = 0)
If Not IsArray(\$aArray) Then
ConsoleWrite(-'Err 1 : Object is not an array' & @CRLF )
SetError(-1)
Return -1
EndIf
Local \$iRows        = Ubound(\$aArray,1) - 1
Local \$iColumns = Ubound(\$aArray,2) - 1
If \$iColumns = -1 then
\$iColumns = 0
EndIf
If \$iRstart > \$iRows  OR  \$iRstart < 0 Then
ConsoleWrite('Err 2 : Requested Start Row out of bounds. (Total Rows: ' & \$iRows & ' Requested Start Row: ' & \$iRstart & ' )' & @CRLF )
SetError(-2)
Return -1
EndIf
If \$iRend > \$iRows Or \$iRend < \$iRstart Then
ConsoleWrite('Err 3 : Requested End Row out of bounds. (Total Rows: ' & \$iRows & ' Requested End Row: ' & \$iRend & ' )' & @CRLF )
SetError(-3)
Return -1
EndIf
If \$iCstart > \$iColumns OR \$iCstart < 0 Then
ConsoleWrite('Err 4 : Requested Start Row out of bounds. (Total Columns: ' & \$iColumns & ' Requested Start Column: ' & \$iCstart & ' )' & @CRLF )
SetError(-4)
Return -1
EndIf
If \$iCend > \$iColumns OR \$iCend < \$iCstart Then
ConsoleWrite('Err 5 : Requested End Row out of bounds. (Total Columns: ' & \$iColumns & ' Requested End Column: ' & \$iCend & ' )' & @CRLF )
SetError(-5)
Return -1
EndIf
Select
Case \$iColumns > 1 ; Requesting data from more than 1 Column in a 2D array
Local \$aResult[\$iRend - \$iRstart + 1][\$iCend - \$iCstart + 1]
For \$i = \$iRstart to \$iRend
For \$ii = \$iCstart to \$iCend
\$aResult[\$i - \$iRstart][\$ii - \$iCstart] = \$aArray[\$i][\$ii]
Next
Next
Case \$iColumns = 1 ; Requesting data from 1 Column in a 2D array
Local \$aResult[\$iRend - \$iRstart + 1]
For \$i = \$iRstart to \$iRend
\$aResult[\$i - \$iRstart] = \$aArray[\$i][\$iCstart]
Next
Case \$iColumns = 0 ; Requesting Data from a 1D array
Local \$aResult[\$iRend - \$iRstart + 1]
For \$i = \$iRstart to \$iRend
\$aResult[\$i - \$iRstart] = \$aArray[\$i]
Next
Case Else
ConsoleWrite('-Err 6 : Unknown Error' & @CRLF )
SetError(-6)
Return -1
EndSelect
Return \$aResult
EndFunc```

ArrayExtract.au3

Edited by Shane0000
Share on other sites
• Moderators
• Solution

Shane0000,

I believe I have fixed the bug and now I need to test a bit more. If you (or anyone else) would care to test as well, here is the new function:

```#include <Array.au3>

Local \$aArray[4][4]
For \$i = 0 To 3
For \$j = 0 To 3
\$aArray[\$i][\$j] = \$i & \$j
Next
Next
_ArrayDisplay(\$aArray, "Original")

Local \$aExtract = _ArrayExtract_Mod(\$aArray, 0, 3, 1, 1)
_ArrayDisplay(\$aExtract, "Row 0-3 column 1")

Local \$aExtract = _ArrayExtract_Mod(\$aArray, 0, 3, 0, 0)
_ArrayDisplay(\$aExtract, "Row 0-3 column 0")

Local \$aExtract = _ArrayExtract_Mod(\$aArray, 1, 1, 1, 3)
_ArrayDisplay(\$aExtract, "Row 1 column 1 - 3")

Local \$aExtract = _ArrayExtract_Mod(\$aArray, 0, 0, 1, 3)
_ArrayDisplay(\$aExtract, "Row 0 column 1 - 3")

Func _ArrayExtract_Mod(Const ByRef \$avArray, \$iStart_Row = -1, \$iEnd_Row = -1, \$iStart_Col = -1, \$iEnd_Col = -1)

If \$iStart_Row = Default Then \$iStart_Row = -1
If \$iEnd_Row = Default Then \$iEnd_Row = -1
If \$iStart_Col = Default Then \$iStart_Col = -1
If \$iEnd_Col = Default Then \$iEnd_Col = -1
If Not IsArray(\$avArray) Then Return SetError(1, 0, -1)
Local \$iDim_1 = UBound(\$avArray, \$UBOUND_ROWS) - 1
If \$iEnd_Row = -1 Then \$iEnd_Row = \$iDim_1
If \$iStart_Row = -1 Then \$iStart_Row = 0
If \$iStart_Row < 0 Or \$iEnd_Row < 0 Then Return SetError(3, 0, -1)
If \$iStart_Row > \$iDim_1 Or \$iEnd_Row > \$iDim_1 Then Return SetError(3, 0, -1)
If \$iStart_Row > \$iEnd_Row Then Return SetError(4, 0, -1)
Switch UBound(\$avArray, \$UBOUND_DIMENSIONS)
Case 1
Local \$aRetArray[\$iEnd_Row - \$iStart_Row + 1]
For \$i = 0 To \$iEnd_Row - \$iStart_Row
\$aRetArray[\$i] = \$avArray[\$i + \$iStart_Row]
Next
Return \$aRetArray
Case 2
Local \$iDim_2 = UBound(\$avArray, \$UBOUND_COLUMNS) - 1
If \$iEnd_Col = -1 Then \$iEnd_Col = \$iDim_2
If \$iStart_Col = -1 Then \$iStart_Col = 0
If \$iStart_Col < 0 Or \$iEnd_Col < 0 Then Return SetError(5, 0, -1)
If \$iStart_Col > \$iDim_2 Or \$iEnd_Col > \$iDim_2 Then Return SetError(5, 0, -1)
If \$iStart_Col > \$iEnd_Col Then Return SetError(6, 0, -1)
If \$iStart_Col = \$iEnd_Col Then
Local \$aRetArray[\$iEnd_Row - \$iStart_Row + 1]
Else
Local \$aRetArray[\$iEnd_Row - \$iStart_Row + 1][\$iEnd_Col - \$iStart_Col + 1]
EndIf
For \$i = 0 To \$iEnd_Row - \$iStart_Row
For \$j = 0 To \$iEnd_Col - \$iStart_Col
If \$iStart_Col = \$iEnd_Col Then
\$aRetArray[\$i] = \$avArray[\$i + \$iStart_Row][\$j + \$iStart_Col]
Else
\$aRetArray[\$i][\$j] = \$avArray[\$i + \$iStart_Row][\$j + \$iStart_Col]
EndIf
Next
Next
Return \$aRetArray
Case Else
Return SetError(2, 0, -1)
EndSwitch

Return 1

EndFunc   ;==>_ArrayExtract_Mod```
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share on other sites

Thanks seems to work as needed.

Overwrote the old one with this one in Array.au3, thanks

Edited by Shane0000
Share on other sites
• Moderators

Shane0000,

Changes to the code and the Help file committed for the next Beta. Thanks for the report.

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Create an account

Register a new account

• Similar Content

• Hi,
How can I get the largest number to be the first number in a calculation? I did the below code but the largest number doesn't store in the \$ aExtract variable. I need always a positive number from the calculation (the largest number be the first in the calculation). Can you help me with that? Thank you.
\$N1 = 33 \$N2 = 45 Local \$numberSort [2] = [\$N1 , \$N2] _ArraySort(\$numberSort, 1) _ArrayDisplay(\$numberSort, "Sort Descending", Default, 1) Local \$aExtract = _ArrayExtract(\$numberSort, 0, 0, 0) _ArrayDisplay(\$aExtract, "Row 1 cols 1") \$minus = \$N1 - \$N2
• By l3ill
Hi Gents,
Updating one of my older scripts here and cant get around this wall...
I want to extract chunks from an larger array of indefinite size as smaller arrays in a loop and work with them individually and then move on to the the next "extracted array" until the original array is empty.
The amount of elements in each extracted array will usually be different so I am using _ArraySearch to find my start and stop points and storing them as variables, which brings me to my problem.
I want to "remove" (delete) the extracted array from the original array each time using _ArrayDelete but it doesnt seem to want me to use variables.
Here is a reproducer:
#include <Array.au3> Local \$aArray[10] For \$i = 0 To 9 \$aArray[\$i] = \$i Next _ArrayDisplay(\$aArray, "Original") \$i_Start = 0 \$i_End = 5 Local \$aExtract = _ArrayExtract(\$aArray, \$i_Start, \$i_End) _ArrayDisplay(\$aExtract, "Extracted Array") Local \$vRange = \$i_Start - \$i_End _ArrayDelete(\$aArray, \$vRange) ;==error 3 - \$vRange is not a valid range string If @error Then MsgBox(0, "error =", @error) EndIf _ArrayDisplay(\$aArray, "After Deletion")Any suggestions would be appreciated :-)
cya,
Bill

edit:  the error I am getting is    3 - \$vRange is not a valid range string
edit 2: BTW this doesn't work either _ArrayDelete(\$aArray, \$i_Start - \$i_End)
• By Guy_
If I wanna be able to "vertically rotate" (scroll up and down) 2D array rows, like...

row 0
row 1
row 2

to

row 2
row 0
row 1

etc. (both directions, where the one that disappears goes to the other end) ...

1) Do I have to make my own function, or is there a simple trick I am missing?
2) If I have to make my own function, would it be more or less like this one I made up?

Problem here is that only "UP" is working...
* I may be missing something very simple...? :-)
* Why can't I seem to get the first row with _ArrayExtract(\$_aArray, 0, 0) somehow anyway...?
#include <Array.au3> HotKeySet("{PGUP}", "_ArrayUp") HotKeySet("{PGDN}", "_ArrayDown") Global \$aArray[3][2] = [["0 ", " car"],["1 ", " bike"],["2 ", " boat"]] ToolTip(_ArrayToString(\$aArray), 0,0) While 1     Sleep(100) WEnd Func _2D_ArrayScroll_vert ( \$_aArray, \$direction = 0 )     Local \$aSplit_1, \$aSplit_2     If \$direction = 0 Then    ; scroll DOWN         ; get all rows except last         \$aSplit_1 = _ArrayExtract(\$_aArray, 0, UBound(\$_aArray) - 2 ) ;~             MsgBox(0,"", _ArrayToString(\$aSplit_1))         ; get last row only         \$aSplit_2 = _ArrayExtract(\$_aArray, UBound(\$_aArray) - 1, UBound(\$_aArray) - 1 ) ;~             MsgBox(0,"", _ArrayToString(\$aSplit_2))         ; \$aSplit_2 = 'last row' + 'all rows except last'         _ArrayAdd(\$aSplit_2, \$aSplit_1)         \$_aArray = \$aSplit_2     Else                    ; scroll UP         \$aSplit_1 = _ArrayExtract(\$_aArray, 1, UBound(\$_aArray) - 1 )             MsgBox(0,"", _ArrayToString(\$aSplit_1)) ; PROBLEM AREA: how to get 1st row of \$_aArray into \$aSplit_2 ? ;~      \$aSplit_2 = \$_aArray[0][2]  ; doesn't work  [1][2] neither         \$aSplit_2 = _ArrayExtract(\$_aArray, 0, 0)  ; doesn't work, other variations get the wrong row, or too many rows             MsgBox(0,"", _ArrayToString(\$aSplit_2))         _ArrayAdd (\$aSplit_1, \$aSplit_2)         \$_aArray = \$aSplit_1     EndIf     \$aArray = \$_aArray     ToolTip(_ArrayToString(\$aArray), 0,0) EndFunc Func _ArrayDown()     _2D_ArrayScroll_vert ( \$aArray ) EndFunc Func _ArrayUp()     _2D_ArrayScroll_vert ( \$aArray, -1 ) EndFunc #cs ; DOWN 0 car 1 bike 2 boat 2 boat 0 car 1 bike ; UP 0 car 1 bike 2 boat 1 bike 2 boat 0 car #ce Thanks!

• Would one of the devs or the akin look at the post below regarding ArrayExtracts inability to extract row 0 and also column 0.
I am unsure of how where to open a ticket.
If I should do this instead can some one provide a link to the ticket page.
Thank you,
Shane
'?do=embed' frameborder='0' data-embedContent>>
×

• Wiki
• AutoIt Resources

• FAQ
×
• Create New...