Well, I am stuck again.

I previously received help on problems with my class/methods.
Now, I am having problems with my colllection code.

I am copying this code, through a step-by-step tutorial, from an Advanced VB book.

I receive the error, "Method or data member not found" on the mDispensaryItems.Add listed below.

Private Sub cmdAdd_Click()
    'Add an item to the collection
   
    If cboFrameSize.ListIndex <> -1 And cboFrameStyle.ListIndex <> -1 Then
        mDispensaryItems.Add cboFrameStyle.ListIndex + 1, cboFrameSize.ListIndex + 1, Val(txtQuantity.Text)
    Else
        MsgBox "Enter values for the item.", vbInformation, "Dispensary Items"
    End If
    cmdClear_Click  'clear out form controls
End Sub

Can someone help me identify where I went wrong?  I am sure it is something I left out, but as I am teaching myself, I do not really know where to go from here.
LVL 3
shawngilbertAsked:
Who is Participating?
 
GPrentice00Commented:
double-check your class.  The error is suggesting that there is no method ".Add" that it can use.
Primary cause:  You haven't put it in the class yet
Secondary cause:  You made it private rather than public in the class.

(If the .Add appears in the Intellitext as you type in the editor, thats good, and yeah, it is exposed, so then the error would be within the code in the class itself, a typo perhaps there too.  If .Add does NOT appear in the intellitext as you type, but other methods/properties do, its definitely because either it doesn't exist, or its not exposed in the class)

0
 
shawngilbertAuthor Commented:
I have my main form, a cDispensaryItem 'class' and a cDispensaryItems 'collection'.  I do not have an Add method in the 'class', nor was one printed for it in the book.

In my collection, I have

Private mDispensaryItems As Collection

and I have

Private Sub Add(ByVal intFrameStyle As Integer, ByVal intFrameSize As Integer, ByVal intQuantity As Integer)

But in my form's code, if I type mDispensaryItems. it only displays Count, Item, NewEnum and Remove as options.

I am trying to learn classes and collections, but finding it very difficult.
0
 
shawngilbertAuthor Commented:
Oh dear.  You are correct.
I reread it and my Add method WAS declared as Private.
Thank you so very much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.