Solved

something wrong with collections

Posted on 2000-03-19
5
165 Views
Last Modified: 2010-05-02
Why doesn't Visual Basic let me add a user defined type structure variable to a collection?
Whenever i try to do that it gives me this compile error message:

"Only user-defined types defined in public object modules can be coerced to or from a variant or pressed to late-bound functions."

Please note that I defined my type strcture in public module. This error happens on this statement

Notes.Add Item:=newnote, Key:=Str(CurNote)

'newnote' is the variable that is declared as type structure. And 'Notes' is my collection.

Any idea?
0
Comment
Question by:mhdhallak
5 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 2634416
"PRB: Can't Use Late Binding When Server Method Uses UDT"
http://support.microsoft.com/support/kb/articles/Q184/8/98.ASP
0
 

Author Comment

by:mhdhallak
ID: 2634452
Adjusted points from 10 to 20
0
 

Author Comment

by:mhdhallak
ID: 2634453
Erick37,

I read that page but it doesn't quite help me because it deals more with activex servers you create. In my case, i am dealing with Collection. I can't possible modify that because it's built in Visual Basic.

so what do you think i should do?

Anybody?
0
 
LVL 27

Accepted Solution

by:
Ark earned 20 total points
ID: 2634617
Hi
What's about making class module Note with Public variables (or Properties) same as in your UDT. Then:
Dim Notes As New Collection
Dim newnote as Note
......
Set newnote = New Note
Notes.Add Item:=newnote, Key:=Str(CurNote)

Cheers

0
 
LVL 1

Expert Comment

by:pclement
ID: 2634705
The standard Collection object will accept any value that can be stored in a Variant. Unfortunately you cannot store a UDT in a Variant.

If you must use the standard Collection object the only alternative is to convert your UDT to a Class as suggested by Ark.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now