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'
}
}
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.