Solved

Running old VB 6 collections in C#

Posted on 2003-11-07
7
219 Views
Last Modified: 2010-04-16
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 ???????????????????????

0
Comment
Question by:Hob_Nob
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:sedmans
ID: 9700961
You have got a foreach statement in C# as well.

The syntax is

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

Author Comment

by:Hob_Nob
ID: 9701366
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?  



0
 
LVL 2

Expert Comment

by:sedmans
ID: 9701442
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.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:Hob_Nob
ID: 9701529
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?
0
 
LVL 2

Expert Comment

by:sedmans
ID: 9702029
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.
}
0
 
LVL 2

Accepted Solution

by:
sedmans earned 150 total points
ID: 9702040
forget my last post.  It has been a long day!

try

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

Author Comment

by:Hob_Nob
ID: 9714475
My code was a bit of a variation on your answer, but basically correct. Thanks alot
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now