Results 1 to 4 of 4

Thread: [RESOLVED] Searching Collection - alternative solution !

Threaded View

  1. #1

    Thread Starter
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Resolved [RESOLVED] Searching Collection - alternative solution !

    Hi Everyone,

    i have 2 collections, one holding a subset of the others data, and i am trying to find out if an item in the smaller collection exists in the bigger collection.

    What i have is a full list of tables & a list of enabled tables. From these i have to extrapolate the disabled tables.

    I do have a solution for this but it is a bit messy and uses On Error Resumes Next which i would like to avoid, so i was wondering if anyone has an alternative solution.

    This is the full sub which basically fills two listbox's. Enabled tables in one & Disabled tables in the other. a user can the move the tables between the list to enable or disable them.

    VB Code:
    1. Dim arrEnabledTables() As String
    2. Dim colEnabledTables As Collection
    3. Dim colAvailableTables As Collection
    4. Dim vitem As Variant
    5. Dim vitem2 As Variant
    6.  
    7. On Error GoTo errorhandler
    8.  
    9. Set mParent = FrmParent
    10.  
    11. Set colAvailableTables = New Collection
    12. Set colEnabledTables = New Collection
    13.  
    14. colAvailableTables.Add "item1", "item1"  'List of All Tables
    15. colAvailableTables.Add "item2", "item2"
    16. colAvailableTables.Add "item3", "item3"
    17. colAvailableTables.Add "item4", "item4"
    18. colAvailableTables.Add "item5", "item5"
    19. colAvailableTables.Add "item6", "item6"
    20. colAvailableTables.Add "item7", "item7"
    21. colAvailableTables.Add "item8", "item8"
    22. colAvailableTables.Add "item9", "item9"
    23. colAvailableTables.Add "item10", "item10"
    24.  
    25. arrEnabledTables = mParent.Application.EnabledTables  'external method that returns an array of enabled tables
    26.  
    27. For n = 0 ToUBound(arrEnabledTables)  'add Enabled Tables to listbox & a collection
    28.      LstEnableTables.AddItem Right(arrEnabledTables(n), Len(arrEnabledTables(n)) - 3)
    29.      colEnabledTables.Add Right(arrEnabledTables(n), Len(arrEnabledTables(n)) - 3), Right(arrEnabledTables(n), Len(arrEnabledTables(n)) - 3)
    30. Next
    31.  
    32. On Error Resume Next
    33. For Each vitem In colAvailableTables  'get Disabled Tables and add them to the other listbox
    34.      vitem2 = colEnabledTables(vitem)
    35.      If IsEmpty(vitem2) Then
    36.           LstDisabledTables.AddItem CStr(vitem)
    37.      End If
    38.      vitem2 = Nothing
    39. Next
    40. On Error GoTo 0

    The reason i have to use OERN is that when you search a collection for an item that is not in it, it throws an error (unlike .Net which if you use an ArrayList it returns a boolean when using the contains method)

    Any ideas for alternatives ?
    Last edited by NeedSomeAnswers; Sep 3rd, 2010 at 04:27 AM.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width