I've try to store the Struct object to Collection, but i failed.
I defined a module contained a custom Struct as below - Public Type Student
-
ID As Integer
-
Name As String
-
End Type
I have another Form as GUI and uses the custom Struct. - Dim Std as Student
-
Std.ID = 1
-
Std.Name = "John"
-
-
Dim Coll as Collection
-
Set Coll = New Collection
-
-
Coll.Add Std, Std.ID
I got the error message as below.
only user-defined types difined in public object modules can be coerced to or from a variant or passed to late-bound functions
Please help me out! - Public Type Student
-
ID As Integer
-
Name As String
-
End Type
The answer is actually quite simple, you cannot use a Collection to contain UDTs (User Defined Types). You can, however, have a Collection of Classes, so convert the Type to a Class.
7 2123
Sakal, what Rabbit is telling you about code tags means in order to post code, click on the "[CODE/]" button and then type or paste your code between the beginning and ending code tags that appear.
Now, as to your problem, we need to see the entire code module for your first bit of code. I've tried just what you have here and I don't have any problem.
Jim
zmbd 5,501
Expert Mod 4TB
Sakal
Before you post the code please follow all of the trouble shooting steps outlined here> > Before Posting (VBA or SQL) Code
Following the troubleshooting steps as outlined will fix a lot of basic issues.
In this case, you more than likely have a mis-classed variable. The debug/compile will should help you to find the issue.
Once you can compile without errors, then run the code. If you are still haveing the same issue then please post back.
thnx
The answer is actually quite simple, you cannot use a Collection to contain UDTs (User Defined Types). You can, however, have a Collection of Classes, so convert the Type to a Class.
I'm learning a lot this week. :)
Life is a learning experience for all of us, isn't it? (LOL).
I'm sorry for this inconvenience of my post.
I've tried the solution of ADezii and it worked. Collection can't store UDTs, but instance object of class instead.
Thanks,
zmbd 5,501
Expert Mod 4TB
Sakal
I'm sorry for this inconvenience of my post
Absolutely no reason to apologize! You have no idea how many people you and ADezii just helped!!!
Would you please select the "best answer?"
thnx
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sanjay |
last post by:
hi,
We are currently porting our project from VB6 to VB .NET.
Earlier we used to make scale transformations on objects like pictureBox ,
forms etc.Now Such transformations are made on the...
|
by: RSB |
last post by:
Hi Every one,
Can i store a Object in the Session variable???
if Yes then HOW?
Thanks RSB
|
by: jordanp |
last post by:
Hello,
I'm having a little trouble here and I'm hoping that somebody might be
able to help me out (win32 console program). First off, I know that I
can use class function inside of my struct as...
|
by: Ashutosh |
last post by:
Hello,
I am a newbie in CSharp.
In C++ if we want to read from socket into the struct object we
directly type cast it as
recv(socketid,(char*),&struct_object,sizeof(struct object))
But C...
|
by: Jay Dee |
last post by:
Object garbage collection of events
I can not help wondering how the garbage collection system handles
events.
If I release all references to an object that has a void that an event
somewhere...
|
by: Humakt |
last post by:
I've seen the solution to do this vice versa, but what if I have an object that has collection and I want to return the objects from query using where clause where I check if any of the items in...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |