Jump to content

<solved> _arrayextract then remove "extracted array" from original array


l3ill
 Share

Recommended Posts

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)

Edited by l3ill
forgot error code
Link to comment
Share on other sites

You have to use the correct syntax, $vRange must be a String not an Integer:

#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")

 

Link to comment
Share on other sites

The forest eluded me as the trees blocked my view...

Thanks Bert !!

I found an additional workaround in case anyone is interested:

As per the help file: $vRange can also be a 1D array listing all rows to be deleted with the count in the [0] element].

So I turned my range into a (non  0 based) array with StringSplit

#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")
;========================================================
$arr_strng = _ArrayToString($aExtract, "|")
ConsoleWrite(" $arr_strng = " & $arr_strng & @CRLF)
$strng_arr = StringSplit($arr_strng, "|")
;========================================================
_ArrayDelete($aArray, $strng_arr)

If @error Then
    MsgBox(0, "error =", @error)
EndIf
_ArrayDisplay($aArray, "After Deletion")

 

Edited by l3ill
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

×
×
  • Create New...