Link to home
Start Free TrialLog in
Avatar of Hob_Nob
Hob_Nob

asked on

Running old VB 6 collections in C#

Hi,
I want to loop around an old VB 6 collection using C#.  The VB collection comes from a dll.

The old VB code that wrote out the collection looked like this:
'********************************************************************
     Dim User, Users
     Set Users = Users.displayList(arg1, arg2, arg3)          'Call the COM object, pass in parameters
     For Each User in Users                                             'Loop around the collection and print
             Response.Write User.firstName
     Next
********************************************************************
I have referenced the dll inside ASP.Net and can create the object, but how do I return the collection and loop around to print out its values?

AD.Users users = new AD.UsersClass();
AD.User user = new AD.UserClass();
// A bit lost now ???????????????????????

Avatar of sedmans
sedmans

You have got a foreach statement in C# as well.

The syntax is

foreach (AD.User user in Users)
{
// work with the items.
}
Avatar of Hob_Nob

ASKER

Cheers sedmans, but before I can loop around the collection, I need to call a function inside the dll that builds the collection according to the arguments passed in.  The same function returns a collection object of users, which I can then print out:

In VB I would use the SET statement:
'*********************************
Set Users = Users.displayList(arg1, arg2, arg3)
For Each User In Users...
*********************************

How do I call the function 'displayList' in class 'Users', pass a collection back and loop around it?  



If the dll is an ActiveX dll then you need to do is add a reference to the dll and then you have access to it.
Avatar of Hob_Nob

ASKER

I have a reference to it, and with Intellisense, I can see my 'displaylist' function, I know it is referenced.  I can't loop around my collection until I call the function 'displaylist' inside the 'Users' class.  

Would the code look anything like this:

AD.User user = new AD.User();
AD.Users users = new AD.Users();
foreach (AD.User user in Users.displayList(arg1, arg2, arg3))
{
// work with the items.
}

Or how do I return the Users collection to a variable in C# so I can then loop around it?
Try,

AD.User user = new AD.User();
AD.Users users = Users.displayList(arg1, arg2, arg3);
foreach (AD.User user in users)
{
// work with the items.
}
ASKER CERTIFIED SOLUTION
Avatar of sedmans
sedmans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hob_Nob

ASKER

My code was a bit of a variation on your answer, but basically correct. Thanks alot