John117 Posted May 5, 2009 Share Posted May 5, 2009 (edited) #include <Array.au3> Local $avArray[11][5] = [ _ ["what", "was", " that", " over", " there"], _ ["", "", "", "", ""], _ ["", "", "", "", "Adverb"], _ ["", "", "Adjective", "", ""], _ ["", "", "", "", ""], _ ["", "", "", "", ""], _ ["", "", "", "", ""], _ ["", "", "Conjunction", "", ""], _ ["", "", "", "Preposition", ""], _ ["Pronoun", "", "", "", ""], _ ["", "Helping verb", "", "", ""]] _ArrayDisplay($avArray) ;~ _ArraySort($avArray, 0, 1, 0, 0) ;~ _ArrayDisplay($avArray, "1") First, I would like to delete all rows that have no data. Second, I would like to collapse the remaining rows. so that there are no blanks. at that point there would only be three rows. -"That" column would have the only entry in the third row. -it has an entry in the second as "Adjective" and the third as "Conjunction" Third, how do I get the total column count? Ubound is rows . . . what is columns?. Thanks! Edited May 6, 2009 by John117 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 5, 2009 Moderators Share Posted May 5, 2009 John117,I believe this will give you what you want - although I have reversed the order of the operations. First we move all the items up to the top of the array - and then delete the empty rows. Otherwise you have to delete the empties twice! Note UBound has parameters to determine which dimension to read - it is all in that fantastic Help file. :-)expandcollapse popup#include <Array.au3> Local $avArray[11][5] = [ _ ["what", "was", " that", " over", " there"], _ ["", "", "", "", ""], _ ["", "", "", "", "Adverb"], _ ["", "", "Adjective", "", ""], _ ["", "", "", "", ""], _ ["", "", "", "", ""], _ ["", "", "", "", ""], _ ["", "", "Conjunction", "", ""], _ ["", "", "", "Preposition", ""], _ ["Pronoun", "", "", "", ""], _ ["", "Helping verb", "", "", ""]] _ArrayDisplay($avArray) For $j = 0 To 4 $iFirst_Empty_Row = 1 For $i = 1 To UBound($avArray) - 1 If $avArray[$i][$j] = "" Then Else $avArray[$iFirst_Empty_Row][$j] = $avArray[$i][$j] If $i <> 1 Then $avArray[$i][$j] = "" $iFirst_Empty_Row += 1 EndIf Next Next _ArrayDisplay($avArray) For $i = 0 To UBound($avArray) - 1 If $i >= UBound($avArray) Then ExitLoop $fEmpty = True For $j = 0 To 4 If $avArray[$i][$j] <> "" Then $fEmpty = False Next If $fEmpty Then _ArrayDelete($avArray, $i) $i -= 1 EndIf Next _ArrayDisplay($avArray) MsgBox(0,"Array Size", "This " & UBound($avArray, 0) & "D array has" & @CRLF & UBound($avArray) & " rows and" & @CRLF & UBound($avArray, 2) & " columns" )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...
John117 Posted May 5, 2009 Author Share Posted May 5, 2009 (edited) :-) UBound (Array,demension) Never noticed that! Testing the rest out now!Of course this is one of the first 2d arrays I have needed . . . Edited May 5, 2009 by John117 Link to comment Share on other sites More sharing options...
John117 Posted May 5, 2009 Author Share Posted May 5, 2009 (edited) Yup! That works! Thanks! Can you tell me what is wrong with this? expandcollapse popup#include <Array.au3> Local $avArray[11][5] = [ _ ["what", "was", " that", " over", " there"], _ ["", "", "", "", ""], _ ["", "", "", "", "Adverb"], _ ["", "", "Adjective", "", ""], _ ["", "", "", "", ""], _ ["", "", "", "", ""], _ ["", "", "", "", ""], _ ["", "", "Conjunction", "", ""], _ ["", "", "", "Preposition", ""], _ ["Pronoun", "", "", "", ""], _ ["", "Helping verb", "", "", ""]] ;_ArrayDisplay($avArray) For $j = 0 To 4 $iFirst_Empty_Row = 1 For $i = 1 To UBound($avArray) - 1 If $avArray[$i][$j] = "" Then Else $avArray[$iFirst_Empty_Row][$j] = $avArray[$i][$j] If $i <> 1 Then $avArray[$i][$j] = "" $iFirst_Empty_Row += 1 EndIf Next Next ;_ArrayDisplay($avArray) For $i = 0 To UBound($avArray) - 1 If $i >= UBound($avArray) Then ExitLoop $fEmpty = True For $j = 0 To 4 If $avArray[$i][$j] <> "" Then $fEmpty = False Next If $fEmpty Then _ArrayDelete($avArray, $i) $i -= 1 EndIf Next ;_ArrayDisplay($avArray) ;MsgBox(0,"Array Size", "This " & UBound($avArray, 0) & "D array has" & @CRLF & UBound($avArray) & " rows and" & @CRLF & UBound($avArray, 2) & " columns" ) $sSearch = "Pronoun" For $i = 1 To UBound($avArray) For $e = 1 To UBound($avArray, 2) $iIndex = _ArraySearch($avArray, $sSearch, $i, 0, 0, 1, $e) If @error Then ConsoleWrite("Not Found " & $sSearch & " was not found on column " & $i & '.' & @CRLF) Else ConsoleWrite("Found " & $sSearch & " was found in the array at position " & $iIndex & ' on column ' & $e & '.' & @CRLF) EndIf Next Next Edited May 5, 2009 by John117 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 5, 2009 Moderators Share Posted May 5, 2009 John117,You do not need to loop through each row and column yourself - _ArraySearch can do some of that work for you with the $iSubItem parameter, which determines the column to search:$sSearch = "Pronoun" For $i = 0 to UBound($avArray, 2) - 1 $iIndex = _ArraySearch($avArray, $sSearch, 0, 0, 0, 0, 1, $i) If $iIndex <> -1 Then ConsoleWrite("Found " & $sSearch & " in the array at Row " & $iIndex & ' Column ' & $i & @CRLF) ExitLoop EndIf Next If $iIndex = -1 Then ConsoleWrite($sSearch & " was not found" & @CRLF)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...
John117 Posted May 5, 2009 Author Share Posted May 5, 2009 That makes sense! What if the word appears twice? Can I get that info also? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2009 Moderators Share Posted May 6, 2009 John117,Look in the Help file for _ArraySearch and take careful note of the $iStart and $iEnd parameters. As you know where you have just found a value, you can use these parameters to restart your search at the appropriate place.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...
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