Changing structure of an arraylist

sijcooke

Member
Joined
Nov 29, 2009
Messages
9
Programming Experience
10+
Hi all, thanks for any help in advance!

I have created a Class Library (dll) with a module and a class in it.
The module declares a structure, and an instance of this structure.

In the class, there is an arraylist declared.

My main program calls a function in the class library class. The class calculates data, stores it in the instanceofstructure. Then adds it to the arraylist.

Once added, it returns the arraylist... to my main program.

Problem:
When i want to use this data in my main program, i get a Cast void error. Its because The structure of the data in the array if of the structure in Class Library module. Is there a way to change the structure of this array to an identicle structure in the main programs Module. When the function returns the arraylist I have tried storing it in a tmp arraylist and copying, cloning etc the data into another arraylist in my main program... still not working. Do i have to loop through all the data and copy each value to a new instanceofstructure, and store this in the new arraylist???

Hope this makes sense!!! Thanks all!
 
The type is that defined in the class lib, so use that type in your main program. Simplified example:
VB.NET:
Shared Function GetSome() As Classlib.Sometype
VB.NET:
Dim var As Classlib.Sometype = Classlib.GetSome()
ArrayList? Forget it, it is a List(Of Object) and why use Object type when you do have the specific type? List(Of Classlib.Sometype) should be it. Or return an array, fill the list and return its ToArray.
 
Thanks for quick reply.
Im bit confused.

The Class Library Module has this:

Public InstanceofStructure as MyStructure
Structure Mystructure
public name as string
public age as integer
end structure

In my main program i want it to use this structure for the instanceofstructure....

In main prog - on form load
dim mainProgramInstance as ClassLibrary1.Mystructure

problem.. it says Type 'ClassLibrary1.MyStructure' is not defined.

Any help so much appreciated. thanks all!
 
The default access modifier for a structure declared at namespace level is Friend, so it will only be available within the assembly that declares it. You have to set it to Public. Always set access modifiers for all elements, it will avoid confusion and uncertainty about such matters.
 

Latest posts

Back
Top