Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / May 2006

Tip: Looking for answers? Try searching our database.

Questions about VB6 Collections

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DreamTribe - 26 May 2006 03:52 GMT
A few questions.. Any help would be appreciated..

1.  Is Microsoft.VisualBasic.Collection or VBA.Collection (from
msvbvm60.dll) compatible with VB 6 Collections?

2.  How would I use VBA.Collection inside c#?

If I do this: (assuming Car class is defined elsewhere)

public class RunThis
{
       public VBA.Collection Garage;

       public RunThis()
       {

           object missing = System.Reflection.Missing.Value;

           Car newCar = new Car("123456");

           // IF I TRY THIS:
           Garage.Add(ref newCar, ref newCar.licensePlate, ref missing, ref
missing);
           // I GET GET : "The 'ref' argument type doesn't match parameter
type

           // IF I TRY THIS:
           Garage.Add(newCar, newCar.licensePlate, ref missing, ref
missing);
           // I GET: Argument has no modifier while parameter has modifier
'ref'

       }
}
"Peter Huang" [MSFT] - 26 May 2006 10:05 GMT
Hi

The collection in VB6 is compatible with the collection in VBA.
But the Microsoft.VisualBasic.Collection is an equivalent in VB.NET for
VB6, so that after you migration, we the code will keep unchanged.

Here are some code snippet for your reference.
VBA.Collection collection= new VBA.CollectionClass();
object item, key, before, after;
key=before=after=null;
item = "pear";
collection.Add(ref item, ref key, ref before, ref after);
item = "apple";
collection.Add(ref item, ref key, ref before, ref after);
VBColl.CCollClass vb = new VBColl.CCollClass();
VBA.Collection collection2 = vb.AddCol( ref collection );
while ( en.MoveNext() )
{
    MessageBox.Show( en.Current.ToString() );
}
Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
DreamTribe - 26 May 2006 16:19 GMT
Hi Peter,

Thank you for the quick reply.

What if I want to add a c# class (derived from object) to a VBA.Collection?
I'm sure this is a simple question, but I can't seem to figure it out.

I can do this:

collection.Add(ref item, ref key, ref before, ref after);

but only if item is of type 'object'.

What if I needed to do  this:

collection.Add(ref myCustomClass, ref myCustomerClass.key, ref before, ref
after);

The compiler tells me "the 'ref' argument type doesn't match parameter
type".

I've tried casting myCustomClass as object but I don't think that works
either..

> Hi
>
[quoted text clipped - 16 lines]
> MessageBox.Show( en.Current.ToString() );
> }
Mattias Sjögren - 26 May 2006 19:13 GMT
>I can do this:
>
[quoted text clipped - 6 lines]
>collection.Add(ref myCustomClass, ref myCustomerClass.key, ref before, ref
>after);

Assign the valuse to object variables first

object x = myCustomClass;
...
collection.Add(ref x, ...);

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.