Jump to content
LoneWolf_2106

Array range and ArrayDelete

Recommended Posts

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.

Share this post


Link to post
Share on other sites
BrewManNH

Read the help file for _ArrayDelete and look at the remarks section. All will become clear to you.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
LoneWolf_2106

You mean that i should specify a range in the following way?

$range_deletion=$first_index&";"&$last_index

If it is so, it didn't work.

Share this post


Link to post
Share on other sites
iamtheky

so can we see the array (or an example), and what you are setting for $first_index and $last_index prior to entering the loop.  If it is indeed the actual last element you are removing you might consider _ArrayPop and just discarding the return.

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
LoneWolf_2106

@iamtheky the Indexes are correct, but arraydelete doesn't delete all the items between the two indexes.

Everything between  $first_index and $last_index must be deleted.

 

Fyi, all the lines before _ArrayDelete are working correctly

 

_ArrayDisplay($aDate_CSV, "My date")

Local $Day=$aDate_CSV[1]
Local $Month=$aDate_CSV[2]
Local $Year=$aDate_CSV[3]

$Day_To_Delete= $Day+1

$sString_To_Delete="INFO ["&$Day_To_Delete&"."&$Month&"."&$Year

$Entry_to_Delete_Indexes_2=_ArrayFindAll($aFile_Array_Original, $sString_To_Delete, 0, 0, 0, 1)
.
.
.
$first_index=$Entry_to_Delete_Indexes_2[0]

$last_index=UBound($aFile_Array_Original) -1

 

My array is a list of entries like the following one:

 

INFO [15.09.2017 19:08:31].......

INFO [15.09.2017 19:08:32].......

INFO [15.09.2017 19:08:33].......

Share this post


Link to post
Share on other sites
iamtheky

the semicolon in your code in post #3 says "this element AND this other element"  you need to use a dash if you want "this element through this other element".

I commented the helpfile example in case its easier to see that way:

#include <Array.au3>

Local $aArray_Base[25][4]
For $i = 0 To 24
    For $j = 0 To 3
        $aArray_Base[$i][$j] = $i & "-" & $j
    Next
Next

; Range string
$aArray = $aArray_Base
Local $sRange = "0;11-15;24"  ;This String removes element 0, elements 11 thru 15, And element 24
_ArrayDisplay($aArray, "BEFORE deletion")
_ArrayDelete($aArray, $sRange)
ConsoleWrite(" " & @error & @CRLF)
_ArrayDisplay($aArray, "RANGE STRING deleted")

 


 
Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
BrewManNH
1 hour ago, LoneWolf_2106 said:

 Is there any way to pass directly the range to ArrayDelete, avoiding the loop?

By the way, you're only avoiding the loop in your own code, _ArrayDelete uses a loop to delete the range.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
LoneWolf_2106

@iamtheky, thanks, it is working, i am testing it

@BrewManNH, thanks for the info, next time i will use just _ArrayDelete without any loop

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

    • l3ill
      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)
    • souldjer777
      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!

       
×