Results 1 to 9 of 9

Thread: dll question and trying to access the internal collection

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    dll question and trying to access the internal collection

    I have a dll I wrote with a collection of items of type item. I want to create a form in the dll that will popup if someone tries to add a property to item that is unique so that they see the item that conflicts with the one they are adding. how can i set a collection to the collection myApp uses in order to reference the same items?

    Example:


    VB Code:
    1. dim myItems as Items
    2. dim myItem as Item
    3.  
    4.  
    5. set myItem = myItems.Add("<YourItemHere>")
    6.  
    7. 'check if myItems collection already has a "<YourItemHere>"

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: dll question and trying to access the internal collection

    You can simply pop msbox:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim cl As New Collection
    3.  
    4. On Error GoTo ErrHandler
    5.  
    6.     cl.Add 1, "1"
    7.     cl.Add 2, "2"
    8.     cl.Add 3, "3"
    9.     cl.Add 4, "4"
    10.    
    11.     cl.Add 1, "1" 'this will generate error because item with idential key already exist
    12.    
    13.     Exit Sub
    14.    
    15. ErrHandler:
    16.    
    17.     MsgBox "Error: " & Err.Number & " - " & Err.Description, vbCritical, "Error"
    18.     Err.Clear
    19.     Exit Sub
    20.  
    21. End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Re: dll question and trying to access the internal collection

    What I am hoping to do is popup a custom form with the name of the item and the conflicting property for both items, the one added and the one being added. This way the user can change the value of the property if they so chose. All of this I would like to have done within the DLL so as not to clutter up my already cluttered application with multiple forms.

    BTW, thanks for the quick reply RhinoBull!

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: dll question and trying to access the internal collection

    It doesn't really matter where you do it - in your app or in the dll - collection still remains a collection... So, if you're assigning some unique key for each new item then you shouldn't have any problem because collections are based on the unique keys. However, if key isn't as important as Item's text then you would have to loop through all items and find match and then pop the message box with that item's text:
    VB Code:
    1. Private Sub Command1_Click()
    2. '============================
    3. Dim cl As New Collection
    4. Dim i As Long
    5. Dim blnExist As Boolean
    6.  
    7.     cl.Add "some new text"
    8.     cl.Add 2
    9.     cl.Add 3
    10.     cl.Add 4
    11.    
    12.     For i = 1 To cl.Count
    13.         If cl.Item(i) = "some new text" Then
    14.             blnExist = True
    15.             Exit For
    16.         End If
    17.     Next i
    18.    
    19.     If Not blnExist Then
    20.         cl.Add "some new text"
    21.     Else
    22.         MsgBox "Item : " & "<some new text>" & " is already included."
    23.     End If
    24.  
    25. End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Re: dll question and trying to access the internal collection

    Ok, i completely understand that point. However, within the DLL is this form. My structure is items - item and item is not creatable. how do i reference the items from within the DLL considering I only know about the mCol that the class builder creates for me when I made my class?

  6. #6

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Re: dll question and trying to access the internal collection

    How can i set a collection to the mCol collection of items when I am not able to select MyDLL.Items class?

    Example:

    dim nItems as MyDLL.Items doesn't work

    dim nItems as Items works but I do not know what to: Set nItems = ??? from within the form inside the DLL.

    I am really sorry for the confution, I am terrible at explaining things, I would be a horrible teacher

  8. #8

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Re: dll question and trying to access the internal collection

    Now, within that form inside the DLL, is it possible to create a object collection of what is already in it without being inside the class module to do it?

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