Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I filter out duplicates from an array collection, but ensure I get the output I need from the collection.

Posted on 2004-09-07
5
Medium Priority
?
280 Views
Last Modified: 2012-05-05
The subject doesnt really give you much insight so let me go into as much detail as possible.

Basically I am trying to take the values out of 2 collections and make sure that the duplicates are omitted, but I need to capture the current value if certain conditions are met.....hmm that may not explain it any clearer.

I am trying to do the following:

   * Check the values in the VP_Positive_Policy_Array against the currently checked values in the Listview, and if any of the values match (as in an INSTR) then flag that current value (or item in the Positive Policy Array) as I will want it 'excluded' from the final output...
   * Check the values in the VP_Negative Policy_Array against the currently checked values in the Listview, and if any of the values match (as in an INSTR) then flag that current value (or item in the Negative Policy Array) as I will want it 'excluded' from the final output...

Now here is where I am stuck.....

   *  If a match is found in one, but not the other (or vice versa) (found in the Positive Array, but not the Negative Array), i need to flag the current value (which will be the current checkitem in the listview), as if either one of these functions find a match, it means it should be flaged as ignored and go onto the next value in the checkitem list (not in the current collection of the array).
   *  Also, If there are NO matches found (meaning the checkeditem value is NOT in the positive OR the negative array), then it needs to display the current results in the listbox.


Here are some example values I am working with and you can assume are your inputs:

ListView1.CheckedItems Values:
  3_PALMTE_412_W2X
  C_ACG_22_W2X
  C_ACG_21_W2K
  3_SMIME_15_W2X

VP_Positive_Policy_Array Values:
  C_ACG_22_W2X
  C_WINZIP_81A_W2K
  C_OFFICE_2KSP3_W2K
    Note:  There are TONS more values but these are the only applicable ones...

VP_Negative_Policy_Array Values:
  C_ACG_21_W2K
  C_REFLECTIONSNAP_805_W2K
    Note:  There are TONS more values but these are the only applicable ones...



With the current code, here is what my tool OUTPUTS in the listbox:

  3_PALMTE_412_W2X  ::   No AD/Policy Found or Application Restricted"
  C_ACG_22_W2X ::   No AD/Policy Found or Application Restricted"
  C_ACG_21_W2K ::   No AD/Policy Found or Application Restricted"
  3_SMIME_15_W2X ::   No AD/Policy Found or Application Restricted"

Note:  Problem is, it shows these values for EVERY item in the array collection (both positive and negative).... I need it so if it finds it ONCE, it doesnt output it again.....

Hope someone can help!!!


*******************START CODE***********************

Private Sub VP_Finalize_Policy_Comparison()
        ''''''''''''''''''Compare the final values with whats selected in the Radia Instance List'''''''''''''''
        ResultListBox.Items.Clear()

        Dim VP_LVItem As ListViewItem
        Dim VP_Current_AppName
        Dim VP_Results_Collection As New ArrayList()

        '''''''''''''''''''''''''''Compare If Positive Values exist, or Negative Values Exist, and determine Results (omit duplicates but continue process)''''''''''''''''''''''''''''''''

        Dim Pos_Flag As Boolean
        Dim Neg_Flag As Boolean
        Dim Neg_Pol_Collection As New ArrayList()

        For Each VP_LVItem In ListView1.CheckedItems
            VP_Current_AppName = VP_LVItem.Text

            Dim Pos_Temp
            For Each Pos_Temp In VP_Positive_Policy_Array
                If Not InStr(Pos_Temp, VP_Current_AppName) > 0 Then

                    Dim Neg_Temp
                    For Each Neg_Temp In VP_Negative_Policy_Array
                        If Not InStr(Neg_Temp, VP_Current_AppName) > 0 Then
                            Dim Test
                            For Each Test In VP_Results_Collection
                                If Not InStr(Test, VP_Current_AppName) > 0 Then
                                    ResultListBox.Items.Add("" & VP_Current_AppName & "   ::   No AD/Policy Found or Application Restricted")
                                End If
                            Next
                        End If
                    Next


                End If
            Next
        Next

*****************END CODE**************************
0
Comment
Question by:phesser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 2000 total points
ID: 12002242
Hi there... try this code...

    Private Sub VP_Finalize_Policy_Comparison()
        Dim SelectedItm As ListViewItem
        For Each SelectedItm In ListView1.SelectedItems
            If Not CheckItm(SelectedItm.Text, VP_Positive_Policy_Array) Then
                If Not CheckItm(SelectedItm.Text, VP_Negative_Policy_Array) Then
                    Dim x As Int16 = -1
                    x = ResultListBox.FindString(SelectedItm.Text)
                    If x = -1 Then
                        ResultListBox.Items.Add(SelectedItm)
                    End If
                End If
            End If
        Next
    End Sub

    Function CheckItm(ByVal Itm As String, ByVal ArrayToSearch As ArrayList) As Boolean
        Dim ArrItm As Object
        For Each ArrItm In ArrayToSearch
            If ArrItm.ToString() = Itm Then
                Return True
                Exit Function
            End If
        Next
        Return False
    End Function

-Baan
0
 

Author Comment

by:phesser
ID: 12002392
Thanks DotNetLover_Baan, I will try this first thing tommorow and let you know...hopefully it will work flawlessly :)
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12006278
Take a look at this:

   Private Sub VP_Finalize_Policy_Comparison()
        Dim VP_LVItem As ListViewItem

        ResultListBox.Items.Clear()

        'Iterate through all items in the ListView
        For Each VP_LVItem In ListView1.CheckedItems

            'If the checked item is not found in either positive or negative list
            'then added to the output listbox
            If Not VP_Negative_Policy_Array.Contains(VP_LVItem.Text) AndAlso _
                Not VP_Positive_Policy_Array.Contains(VP_LVItem.Text) Then

                'If the checked item was already added to the output listbox
                'don't add it again in order to avoid duplicates in the output
                If Not ResultListBox.Items.Contains(VP_LVItem.Text) Then
                    'the was not found, so we can add it to the output list box

                    ResultListBox.Items.Add(VP_LVItem.Text)
                End If
            End If
        Next
    End Sub
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12006434
I can see DotNetLover_Baan and my code do the same thing.

I posted my code since i did last night and don't have access to internet in my house.

You don't need to iterate an arraylist to find an item, you can use

 VP_Negative_Policy_Array.Contains

 If Not VP_Negative_Policy_Array.Contains(VP_LVItem.Text) AndAlso _
                Not VP_Positive_Policy_Array.Contains(VP_LVItem.Text) Then

AndAlso means that if the first condition becomes false do not evaluate the second.

The same contains in the listbox.
 ResultListBox.Items.Contains
0
 

Author Comment

by:phesser
ID: 12006517
That looks to have worked DotNetLover_Baan...really appreciate the quick and accurate turnaround!

Also wguerram, thanks for your input, sorry about accepting before I noticed your solution as well...gives me some great insight into the process and works as well...!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question