Jump to content

Array help. -still need to get duplicates in search . . .


Recommended Posts

#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 by John117
Link to comment
Share on other sites

  • Moderators

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

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Yup! That works! Thanks!

Can you tell me what is wrong with this?

#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 by John117
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...