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:
dim myItems as Items
dim myItem as Item
set myItem = myItems.Add("<YourItemHere>")
'check if myItems collection already has a "<YourItemHere>"
Re: dll question and trying to access the internal collection
You can simply pop msbox:
VB Code:
Private Sub Command1_Click()
Dim cl As New Collection
On Error GoTo ErrHandler
cl.Add 1, "1"
cl.Add 2, "2"
cl.Add 3, "3"
cl.Add 4, "4"
cl.Add 1, "1" 'this will generate error because item with idential key already exist
Exit Sub
ErrHandler:
MsgBox "Error: " & Err.Number & " - " & Err.Description, vbCritical, "Error"
Err.Clear
Exit Sub
End Sub
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!
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:
Private Sub Command1_Click()
'============================
Dim cl As New Collection
Dim i As Long
Dim blnExist As Boolean
cl.Add "some new text"
cl.Add 2
cl.Add 3
cl.Add 4
For i = 1 To cl.Count
If cl.Item(i) = "some new text" Then
blnExist = True
Exit For
End If
Next i
If Not blnExist Then
cl.Add "some new text"
Else
MsgBox "Item : " & "<some new text>" & " is already included."
End If
End Sub
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?
Re: dll question and trying to access the internal collection
So, instead of MsgBox display your form with whatever message you need. Message could be displayed in an ordinary Label control. I don't really understand what makes you confused. :confused:
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 :)
1 Attachment(s)
Re: dll question and trying to access the internal collection
See attachments for a very basic sample project (open Group1.vbg).
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?