Setting a VB6 Collection to a .NET Collection



  • 1. how to print a report from access to excel using vb code
    Does anyone know how to print a report from access to excel using vb code within the access database? Thanks
  • 2. Installing VB6 and .NET on one computer
    For various reasons, I am looking at installing .NET on a machine that already has VB6 installed. I am not looking at removing VB6. Are there any conflicts/problems with doing the above? Thanks, Seanna
  • 3. OT: How To Monitor A File For Changes
    Hi Cor, LOL G'night ;-) Fergus
  • 4. Crystal distribution
    What do I have to have on the client machine to run Crytal .NET reports? I realized that there are many references in a project to Crystal dlls in the GAC. How can I install these ones on the client? thanks,
  • 5. IsDate Error
    I just upgraded a V 6.0 app. to .Net. I keep getting an error from a simple IsDate statement. Basically checking to see if the value of a variable(vValue = "A2957") is a date example - If IsDate(vValue)=False then The error message is "A first chance exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: The string was not recognized as a valid DateTime. There is a unknown word starting at index 0." Anyone seen this and know a way around it.

Setting a VB6 Collection to a .NET Collection

Postby google » Wed, 23 Feb 2005 06:07:07 GMT

I am developing an ASP.NET application and calling a COM object to
access functions within an internally active application.
I am able to set most properties within the COM object class, but
cannot set the VB6 collection to the .NET collection.

The property is in VB6 as follows:

    Public Property Let MyCol(ByVal Value As Collection)
         Set colMyCol = Value
    End Property

The code in the page is as follows: (Note that colInfo has the
same properties as MyCol):

    Dim objX as object
    objX = Server.CreateObject("VB6DLL.VB6CLASS")

    If Not Session("MyCol") Is Nothing Then
        objX.MyCol = colInfo
    End If

Basically, I'm looking for a known way to map a collection from .NET
back to VB6.


RE: Setting a VB6 Collection to a .NET Collection

Postby QWxpZW4yXzUx » Wed, 23 Feb 2005 07:19:06 GMT

What's being stored in the collection, is it a intrinsic...? I think you'll 
have to iterate through the VB6 collection and copy the children to the .Net 
types manually.

Similar Threads:

1.Collection as sub-set of collection

This is about VB6, hope this is the right forum!

Say I have two collections: Cars and Manufacturers e.g.,

Cars = Focus, Escort, Puma, Cougar, 626, 323, Clio, Espace, 106, 206,

Manufacturers = Ford, Mazda, Renault, Peugeot

I have a couple of questions about inter-referencing between them:

1) Can each 'Car' reference the appropriate 'Manufacturer' object, such
that Cars("Focus").Manufacturer returns (a reference to) the same
object as Manufacturers("Ford")?

2) Can each 'Manufacturer' contain a 'MyCars' collection which is
essentially a subset of the 'Cars' collection, BUT REFERENCES THE SAME
OBJECTS. That is, say, if I do

Manufacturers("Ford") .MyCars("Focus").Age = 6


n = Cars("Focus").Age

n = 6

If this can be done, how?
If it can only be simulated, what is the best method?

Thanks very much,


2.Nester Collection, Collection within collection


Is it possible to create a collection within another collection.
Here is the abstract of my object:
* Class 1  (consists of)
  - Attr 1a
  - Attr 1b
  - Col 1 (collection of class 2)
     * Class 2 (consists of)
       - Attr 2a
       - Attr 2b
       - Col 2 (collection of class 3)

The db relation is Many to Many and I normalised to M-1-M, and I want to 
impletement the same in the collection.

My second question:
I am using the creating collection method suggested in the MSDN disc e.g.:
in Class 2
    Attr 2a (property Get/Let)
    Attr 2b (property Get/Let)
    Collection 2 (read from db and get all relevants entries and use Add 
method attach
       to the collection)

the collection 2's items are "populated" in this same module.  That leads to 
my question:

It is like a cascade method and each class "populates" its own collection 
items ?
the highest level class does ALL the "populating" the collection items and 
sub-collection items?

I hope I have made myself clear.  Thanks very much

Chwan Keng

3.Inheriting VB6 dll classes/collections into dotnet classes/collections


Currently what I am doing is inheriting vb6 classes into dotnet classes like

Public Class CEmploye
   Inherits VB6DLLFile.clsEmploye
End Clas

This seems to work fine.  My problem is inheriting a collection from the VB6 dll file.  For example if I have a collection of Employees.  Would it look like this

Public Class CEmployeeCollectio
  Inherits VB6DLLFile.colEmployee
End Clas

How would I access the collection in a For Each loop?  Currently I have something that looks like this

For Each CEmployee In CEmployeeCollection 'I am skipping all the Dim something As New Class stuff

I am getting a "Specified cast is not valid" error message with the above lines

I do not understand why.  I am looking for anyone that can explain why that is happening


4.Collection problems (create Collection object, add data to collection, bind collection to datagrid)

I try to make my own ArticleAttribute object and ArticleAttributeCollection, 
and add data to this Collection. It almost works, but the problem is that 
each time I add an ArticleAttribute to my Collection, it seems like it 
overwrites the other ArticleAttributes. When bind the 
ArticleAttributeCollection to a datagrid, all articleattributes are the 

This is what my datagrid dispays:

ID   Content
2     Hello 2
2     Hello 2
2     Hello 2

It should be like this:

ID   Content
0     Hello 0
1     Hello 1
2     Hello 2

Here is my ArticleAttributeCollection.cs

namespace Test
    public class ArticleAttributeCollection : CollectionBase, IEnumerable

        public void Insert(int index, ArticleAttribute ArticleAttribute)
            base.List.Insert(index, ArticleAttribute);

        public void Add(ArticleAttribute ArticleAttribute)

        public void Remove(ArticleAttribute ArticleAttribute)

        public ArticleAttribute this[int index]
                return (ArticleAttribute)(base.List[index]);
                base.List[index] = value;


Here is my ArticleAttribute.cs

namespace Test
    public class ArticleAttribute

        public ArticleAttribute()

        public ArticleAttribute(int templateDefinitionId, int articleId, 
string content, string templateDefinitionName, string 
            this._TemplateDefinitionId = templateDefinitionId;
            this.ArticleId = articleId;
            this.Content = content;
            this.TemplateDefinitionName = templateDefinitionName;
            this.TemplateDefinitionHelpText = templateDefinitionHelpText;

        private int _TemplateDefinitionId;
        public int TemplateDefinitionId
            get { return _TemplateDefinitionId; }
            set { _TemplateDefinitionId = value; }

        private int _ArticleId;
        public int ArticleId
            get { return _ArticleId; }
            set { _ArticleId = value; }

        private string _Content;
        public string Content
            get { return _Content; }
            set { _Content = value; }

        private string _TemplateDefinitionName;
        public string TemplateDefinitionName
            get { return _TemplateDefinitionName; }
            set { _TemplateDefinitionName = value; }

        private string _TemplateDefinitionHelpText;
        public string TemplateDefinitionHelpText
            get { return _TemplateDefinitionHelpText; }
            set { _TemplateDefinitionHelpText = value; }


Here I adds articleAttributes to the Collection, and bind it to a datagrid.
It returns 3 items, all with the same ID and Content... Why??

protected void Page_Load(object sender, EventArgs e)
    Test.ArticleAttributeCollection ArticleAttributeCollection = new 
    Test.ArticleAttribute ArticleAttribute = new Test.ArticleAttribute();

    int i = 0;

    while (i<2)
        ArticleAttribute.ArticleId = i;
        ArticleAttribute.Content = "Innhold " + i;


    this.dtgTest.DataSource = ArticleAttributeCollection;


Return to VB.NET


Who is online

Users browsing this forum: No registered users and 63 guest