Stoex Posted May 5, 2014 Share Posted May 5, 2014 I saw this code on the site and have attempted to modify it so I could delete elements in a 2D array if a given column was 0. I keep running into errors, so could somebody please let me know how it would change. Thanks. #include <Constants.au3> #include <Array.au3> Local $aArray[4][3] = [["col 0", "col1", "col2"], ["abc", "efg", "123"], ["", "", ""], ["hij", "", "xyz"]] Local $iCount = 0, $sTemp _ArrayDisplay($aArray) For $i = 0 To UBound($aArray, 1) - 1 $sTemp = "" For $j = 0 To UBound($aArray, 2) - 1 $aArray[ $iCount][$j] = $aArray[$i][$j] $sTemp &= $aArray[$i][$j] Next If $sTemp <> "" Then $iCount += 1 Next Link to comment Share on other sites More sharing options...
jdelaney Posted May 5, 2014 Share Posted May 5, 2014 how about (not sure if this is what you need) #include <Constants.au3> #include <Array.au3> Local $aArray[6][3] = [["col 0", "col1", "col2"], ["", "", ""], ["", "", ""], ["abc", "efg", "123"], ["", "", ""], ["hij", "", "xyz"]] Local $iCount = 0, $sTemp _ArrayDisplay($aArray) For $i = UBound($aArray) - 1 To 0 Step -1 $bRemove = True For $j = 0 To UBound($aArray,2) - 1 If StringLen($aArray[$i][$j]) > 0 Then $bRemove = False ExitLoop EndIf Next If $bRemove Then For $x = $i To UBound($aArray) - 1 If $x < UBound($aArray) - 1 Then For $j = 0 To UBound($aArray,2) - 1 $aArray[$x][$j] = $aArray[$x+1][$j] Next EndIf Next ReDim $aArray[UBound($aArray)-1][UBound($aArray,2)] EndIf Next _ArrayDisplay($aArray) It's removing empty rows, but you can modify to only remove if some column is empty IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
jguinch Posted May 6, 2014 Share Posted May 6, 2014 Stoex, the purpose of your code is to >Delete blanks from 2D arrays Is it really what you need to do ? What do you want to delete depending on the column 0 ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Stoex Posted May 6, 2014 Author Share Posted May 6, 2014 jguinch I couldn't remember who the code was written by, but looks like its you. You first code (above) was great in assisting me to learn more about this array stuff. My goal then was to delete elements where a blank occurred. I then looked to delete elements based upon a 0 (zero) instead of a blank. I tried to simply modify what you originally coded but cannot get it to work and thus I go in circles. So now in a 2D array I'm looking to delete a "row" if a 0 shows up in a column in that row. For instance in your code: If $sTemp <> "" Then $iCount += 1 I just replaced the "" with a zero, but its not working. Looked to me as if it doesn't equal 0, keep it. Guess I'm missing something. Link to comment Share on other sites More sharing options...
jguinch Posted May 6, 2014 Share Posted May 6, 2014 (edited) Something like this ? #include <Array.au3> Local $aArray[4][3] = [["col 0", "col1", "col2"], ["abc", "efg", 0], ["abc", 0, "def"], ["hij", "klm", "nop"]] Local $iCount = 0, $sTemp For $i = 0 To UBound($aArray, 1) - 1 $iDelete = 0 For $j = 0 To UBound($aArray, 2) - 1 $aArray[ $iCount][$j] = $aArray[$i][$j] If $aArray[$i][$j] == 0 OR $aArray[$i][$j] = "" Then $iDelete = 1 Next If NOT $iDelete Then $iCount += 1 Next Redim $aArray[ $iCount][UBound($aArray, 2) ] _ArrayDisplay($aArray) Edited May 6, 2014 by jguinch Stoex 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Stoex Posted May 6, 2014 Author Share Posted May 6, 2014 jguinch that seems similar to your first one, in which I was looking to remove blanks. The goal was to read the array and delete rows where a column could contain a blank or a 0. I just tried using both your codes, one right after the other - first remove blanks, then remove 0's. I have something wrong since the 0's are deleted but the blanks remain. Link to comment Share on other sites More sharing options...
Stoex Posted May 6, 2014 Author Share Posted May 6, 2014 jdelaney i tried your code after modifying it and it worked, I also ran it 1. to delete blanks and 2. to delete 0's. It works. Not saying I fully get it, since I am new at all this. Link to comment Share on other sites More sharing options...
jguinch Posted May 6, 2014 Share Posted May 6, 2014 Stoex, my last code used to suppress rows containing a column equal to 0. I edited it to allow suppress of rows for blanks to. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Stoex Posted May 6, 2014 Author Share Posted May 6, 2014 jguinch Nice! Hits both. For me, as a beginner, I find shorter execution routes allow me to understand it better. Otherwise I can get lost. 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