Jump to content

Array range and ArrayDelete


Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

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