BasementDweller Posted January 30, 2019 Share Posted January 30, 2019 (edited) Greetings, Using _ArrayDelete, I have not been successful trying to delete multiple rows that contain the same value. The value is located in the same 2D array column. I receive the error (427) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Referring to the script below, _ArrayDisplay($aArray) does return all of the data from the "MyData.csv" file. The value "28" is always located in $aArray's Col0. The number of rows in the csv file changes daily and the number of columns remains the same. ArrayDisplay($vRange) returns all of the row numbers that contain "28", and lists these row numbers in a single Col0 (please see attached screenshot). The help file's Remarks for _ArrayDelete state: "$vRange can also be a 1D array listing all rows to be deleted with the count in the [0] element]." My (very new to scripting) interpritation of this remark is that $vRange fulfills the requirements. I searched this forum and the Internet, and didn't find anything I thought was useful. I hope someone can show me the error of my ways. Thank you! #include <Array.au3> #include <File.au3> #include <CSV.au3> #include <String.au3> #include <SFTPEx.au3> #include <MsgBoxConstants.au3> $path = @ScriptDir&"\" $aArray=_ParseCSV($path&"MyData.csv") _ArrayDisplay($aArray) $vRange=_ArrayFindAll($aArray, "28", Default, Default, Default, Default, 0) _ArrayDisplay ($vRange) _ArrayDelete($aArray, $vRange) Edited January 30, 2019 by BasementDweller Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 30, 2019 Moderators Share Posted January 30, 2019 BasementDweller, _ArrayFindAll returns an array - _ArrayDelete requires a delimited string as a range. Therein lies your problem. Convert the array into string using _ArrayToString and setting the $sDelim_Col parameter to ";" will give you a formatted string that _ArrayDelete will accept: #include <Array.au3> Global $aArray[20] For $i = 0 To 19 $aArray[$i] = Random(1, 5, 1) Next _ArrayDisplay($aArray) $vRange =_ArrayFindAll($aArray, "2", Default, Default, Default, Default, 0) _ArrayDisplay ($vRange) $vRange = _ArrayToString($vRange, ";") ConsoleWrite($vRange & @CRLF) _ArrayDelete($aArray, $vRange) _ArrayDisplay($aArray) M23 Subz, beautifulsoup and Redshift 3 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
xcaliber13 Posted January 30, 2019 Share Posted January 30, 2019 I do a similar process with a daily csv file. I have to delete rows that contain different numbers. For example I need to delete every row that contains the number 72275. I use a function that I found on this forum. Here is the code: Global $aArray _FileReadToArray ( 'Pathtoyourfile\Yourfilename.csv', $aArray ) $aArray = _DeleteArrayElementWithStringInstr ( $aArray, '72275' ) ; The 72275 can be any string to search for _FileWriteFromArray ( 'Pathtoyourfile\Yourfilename.csv', $aArray, 1 ) ;The funtion Func _DeleteArrayElementWithStringInstr ( $aArray, $_String ) Local $_Item For $_Element In $aArray If StringInStr ( $_Element, $_String ) <> 0 Then _ArrayDelete ( $aArray, $_Item ) Else $_Item+=1 EndIf Next Return ( $aArray ) EndFunc ;==> _DeleteArrayElementWithStringInstr ( ) Just another way to do it. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 30, 2019 Moderators Share Posted January 30, 2019 xcaliber13, That is a dreadfully slow way to do it as you will call ReDim (one of the slowest functions in AutoIt) every time you delete a line. Using _ArrayDelete with a range only calls ReDim once per call - which is why I wrote it that way! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BasementDweller Posted January 31, 2019 Author Share Posted January 31, 2019 (edited) M23 -- I greatly appreciate your suggestion, which worked perfectly. Additionally, I took a look at your UDF's. They are inspiring. I hope to be able to write my own UDFs some day. And to both you and xcaliber13 -- Thank you very much for taking the time to comment! Edited January 31, 2019 by BasementDweller Link to comment Share on other sites More sharing options...
Nine Posted January 31, 2019 Share Posted January 31, 2019 $vRange : Element(s) to delete - either a single index, a range string or a 1D array with a count in the [0] element You can use an array to delete but you must provide a count at first, which is something that _ArrayFindAll doesn't provide “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 31, 2019 Moderators Share Posted January 31, 2019 Nine, Well spotted! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BasementDweller Posted February 1, 2019 Author Share Posted February 1, 2019 22 hours ago, Nine said: $vRange : Element(s) to delete - either a single index, a range string or a 1D array with a count in the [0] element You can use an array to delete but you must provide a count at first, which is something that _ArrayFindAll doesn't provide Hi Nine -- Will you please show me what is meant by a 1D array with a count in the [0] element, compared to a 1D array without a count in the [0] element? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 1, 2019 Moderators Share Posted February 1, 2019 BasementDweller, A 1D array with a count looks like this: Local $aArray[] = [4, 1, 2, 3, 4] whereas without a count it looks like this: Local $aArray[] = [1, 2, 3, 4] There is no functional difference between the 2 types - you can easily get the count by using UBound - so it is a matter of personal choice. Many AutoIt functions return arrays with a count in the [0] element - unfortunately for you _ArrayFindAll does not so you would need to do something like this to convert the returned array: #include <Array.au3> ; Simulate no-count array returned from _ArrayFindAll Local $aArray[] = [1, 2, 3, 4] ; Add a count into the [0] element _ArrayInsert($aArray, 0, UBound($aArray)) ; And here is the array with a count _ArrayDisplay($aArray, "", Default, 8) So now you have 2 ways to skin this particular cat - your choice! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Nine Posted February 1, 2019 Share Posted February 1, 2019 (edited) Try : ;your code here $vRange=_ArrayFindAll($aArray, "28", Default, Default, Default, Default, 0) _ArrayInsert ($vRange,0,ubound($vRange)) _ArrayDelete($aArray, $vRange) M23 you are too fast Edited February 1, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
BasementDweller Posted February 1, 2019 Author Share Posted February 1, 2019 Thanks for being so helpful. Just to be sure I understand -- Am I correct to say that a count in the [0] element of a 1D array is a number that always refers to the total number of rows of the array? And a followup question, please: Is there a [0] element in a 2D array? Link to comment Share on other sites More sharing options...
Nine Posted February 1, 2019 Share Posted February 1, 2019 22 minutes ago, BasementDweller said: Am I correct to say that a count in the [0] element of a 1D array is a number that always refers to the total number of rows of the array? No it is just one of the way to implement a count 23 minutes ago, BasementDweller said: And a followup question, please: Is there a [0] element in a 2D array? Again no, for the same reason as above... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 1, 2019 Moderators Share Posted February 1, 2019 BasementDweller, The [0] element is an element like all of the other elements. It is not exclusively used as a count - it can be used for anything. Hence the need to read the Help file carefully to see what exactly is in, or required to be in, a particular array with which you are dealing. A 2D array does not have a [0] element - but does have a [0][0] element - which similarly can be used for a count, although not necessarily. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BasementDweller Posted February 1, 2019 Author Share Posted February 1, 2019 Very nice. Thank you for your help! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now