Sign in to follow this  
Followers 0
souldjer777

2d ArraySearch for Column Element and ArrayDelete Element Row

7 posts in this topic

#1 ·  Posted (edited)

Good Evening All,

So... I dug around AutoIT forums and I'm still going out of my mind ;) (nothing new) trying to figure out how to loop through my entire 2d array with a search - and delete the entire array ROW that matched up to my search criteria. Something like...

I'm trying to find anything in my array that matches "_FDL" or whatever criteria necessary and DELETE the ENTIRE ROW, next, next next...

My array now has 12 Columns and about 350 rows - so far I can't delete "beans" lol.

For $element = UBound($aSP_WorkflowMain01) - 1 To 1 Step -1
If _ArraySearch($aSP_WorkflowMain01[$element], "_FDL",0, 0, 0, 1, 0, 1 ) <> -1 Then
_ArrayDelete($aSP_WorkflowMain01, $element)
EndIf
Next
_ArrayDisplay ($aSP_WorkflowMain01, "Total Array - FDL")

It's late soooo... ya know. lol

I love AutoIT - no freakin question - just some things are always going to be over my head - sry.

:ILA2:

Edited by souldjer777

"Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"
Song Title: I guess you could say
Artist: Middle Class Rut

Share this post


Link to post
Share on other sites



Is the search phrase in only one column of the array all of the time? Use _ArraySearch to find the "row" that the phrase was found at, then you can use _ArrayDelete to delete that row.


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

Hi BrewManNH,

Yes, in this particular case I believe it is in just one row that I was to search for _FDL entries.

So, what am I doing wrong here? Will this loop go through an entire 2d array column deleting all the "_FDL" entry rows?

Sorry I didn't get back sooner - at about 10:30 EST I was having trouble accessing the Forum (probably my pc).

For $element = UBound($aSP_WorkflowMain01) - 1 To 1 Step -1
If _ArraySearch($aSP_WorkflowMain01[$element], "_FDL",0, 0, 0, 1, 0, 1 ) <> -1
Then _ArrayDelete($aSP_WorkflowMain01, $element)
EndIf
Next _ArrayDisplay ($aSP_WorkflowMain01, "Total Array - FDL")

"Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"
Song Title: I guess you could say
Artist: Middle Class Rut

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

_ArraySearch searches an array, not an element of the array.

This might work for you, untested so it might need tweaking

While 1
$element = _ArraySearch($aSP_WorkflowMain01, "_FDL", 0, 0, 0, 1, 0, 1)
    If $element >= 0 Then ; _FDL was found if >= 0
        _ArrayDelete($aSP_WorkflowMain01, $element) ; delete the element
        If Not IsArray($aSP_WorkflowMain01) Then ExitLoop ; if the array is empty after the delete, exit the loop
    Else ; _FDL wasn't found
        ExitLoop ; exit the While loop
    EndIf
WEnd
Edited by BrewManNH
1 person likes this

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

#5 ·  Posted (edited)

(earlier) Thank you for the reply BrewManNH and thanks for the help! I'll check it out right now!

(later) Yes! It worked! Thank you BrewManNH! I know you guys don't always like submitting code for folks and I hate asking, I really do it's like a last resort but I'm no programmer (not yet ;) ) ... I've tried on my own believe me... thank you so much!!! Woohoo!

While 1
$element = _ArraySearch($aSP_WorkflowMain01, "_FDL", 0, 0, 0, 1, 1, 0)
If $element >= 0 Then ; _FDL was found if >= 0 ; _FDL was found
_ArrayDelete($aSP_WorkflowMain01, $element) ; delete the element
If Not IsArray($aSP_WorkflowMain01) Then ExitLoop ; if the array is empty after the delete, exit the loop
Else ; _FDL wasn't found
ExitLoop ; exit the While loop
EndIf
WEnd

Worked like a charm!

Edited by souldjer777

"Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"
Song Title: I guess you could say
Artist: Middle Class Rut

Share this post


Link to post
Share on other sites

FYI - A while back this worked but it would only pick up on EXACT strings in the 2d array which didn't work if any change to the element was made.

:oops:

For $i = Ubound($aNewArray) - 1 to 0 Step - 1
If $aNewArray[$i] == "_FDL " Or $aNewArray[$i] == "_RRT" then _ArrayDelete($aNewArray, $i)
Next

BrewManNH got it working with the loop that searches any "like" elements here... which totally rocks :guitar:

While 1
$element = _ArraySearch($aSP_WorkflowMain01, "_FDL", 0, 0, 0, 1, 1, 0)
If $element >= 0 Then ; _FDL was found if >= 0 ; _FDL was found
_ArrayDelete($aSP_WorkflowMain01, $element) ; delete the element
If Not IsArray($aSP_WorkflowMain01) Then ExitLoop ; if the array is empty after the delete, exit the loop
Else ; _FDL wasn't found
ExitLoop ; exit the While loop
EndIf
WEnd

:graduated: - Thanks again!


"Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"
Song Title: I guess you could say
Artist: Middle Class Rut

Share this post


Link to post
Share on other sites

The reason it only matched on exact matches, I'm assuming you mean case sensitive matches, was because you used "==" instead of "=", "==" is for case sensitive string comparisons.


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

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
Sign in to follow this  
Followers 0