Jump to content
l3ill

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

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

Share this post


Link to post
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")

 

Share this post


Link to post
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

Share this post


Link to post
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

  • Similar Content

    • By Deye
      just needed this post to get a clue of how well will this do as an alternative to searching the the array @deleting empty rows 1D & 2D speed wise
      Note: for the 1D the method doesn't work if the chosen delimiter exists in any of the array elements ..(not about the "|" one) 
      So Here is an all around fast combo that includes @Inpho's _ArrayFindEmptyRows()  that proved to be a very fast way for removing 2D empty rows 
       
    • By ramin92003
      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 LoneWolf_2106
      Hi,
      i would like to specify the array range to delete some items in my array. I don't know why the resulting array is the same.
      Here is my code:
       
      While $last_index >= $first_index _ArrayDelete($aFile_Array_Original, $aFile_Array_Original[$last_index]) $last_index-=1 WEnd  Is there any way to pass directly the range to ArrayDelete, avoiding the loop?
      Thanks in advance.
    • By souldjer777
      Good Morning AutoIT Gurus and Masters
      Slightly complicated array here... and infinite loop that I'm trying to output to a file after the values are matched up; then anything that doesn't match is deleted from the array and finally written to a file...
      This guy does an infinite loop... and I'm not sure why... I tried to put in message boxes - but there are 20K records so I couldn't click through that many. LOL.
      #RequireAdmin #include <array.au3> #include <file.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> Global $WXYZArray01, $array01, $ProgramTitle, $sleeptime, $k01 $ProgramTitle = "Testing 1 2 3" $sleeptime = 1000 _FileReadToArray(@ScriptDir & "\" & "testing_output_csv_unique_values.csv", $array01, "", ",") ;_ArrayDisplay ($array01, "Array01") $aUniqueHostname = _ArrayUnique ($array01, 1) ;_ArrayDisplay ($aUniqueHostname, "UniqueHostname ") For $i01 = Ubound($aUniqueHostname) - 1 to 0 Step - 1 For $j01 = Ubound($array01) - 1 to 0 Step - 1 If $array01[$j01][1] == $aUniqueHostname[$i01] and StringRegExp($array01[$j01][5], "MY_VALUE") then MsgBox(0, "Computer and MY_VALUE", $aUniqueHostname[$i01] & " : " & $array01[$j01][5]) $FileName01 = @ScriptDir & "\" & $array01[$j01][3] & "_" & $aUniqueHostname[$i01] & "_" & $array01[$j01][2] & ".csv" MsgBox(0, "File Name", $FileName01) $WXYZArray01 = $array01 _ArrayDisplay ($WXYZArray01, "WXYZ Array") SplashTextOn($ProgramTitle, 'Generic - Please wait for loop to complete...', 400, 40, -1, -1, 2, "", 10) Sleep ($sleeptime) For $k01 = 0 To Ubound($WXYZArray01) - 1 ; MsgBox (0, "In the WXYZ loop", $WXYZArray01[$k01][1] & " : " & $aUniqueHostname[$i01]) If $WXYZArray01[$k01][1] <> $aUniqueHostname[$i01] Then ;MsgBox (0, "In the WXYZ loop - Delete", $WXYZArray01[$k01][1] & " : " & $aUniqueHostname[$i01]) _ArrayDelete($WXYZArray01, $k01) ;_ArrayDisplay ($WXYZArray01) $k01 -= 1 EndIf If $k01 = UBound($WXYZArray01) - 1 Then ExitLoop Next SplashOff() MsgBox (0, "Out of the WXYZ loop", "Out of the WXYZ loop - File Write From Array") _FileWriteFromArray($FileName01, $WXYZArray01, 1) ExitLoop EndIf Next Next I'm hoping someone here can tell me why at a glance... I'm a little burned out to see the answer... feeling toasty LOL 
      Thank you everyone for your help!

       
    • 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! 
×
×
  • Create New...