Solved

something wrong with collections

Posted on 2000-03-19
5
171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 28

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Run code from text file in vb 1 103
Notepad++ how to remove delimiter : from beggning of the line? 3 136
Spell Check in VB6 13 151
VBA Replace Function - What am I missing? 3 52
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

752 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