473,508 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB6 referencing a .NET Hashtable

I'm working on using the COM Interop wrapper on an existing .NET library, to
allow existing VB6 applications to call the .NET code.
And I've been able to get it working in a basic sense (I can return basic
types like strings and booleans, and I've added a reference to MSCORLIB.tlb
so I can even return Hashtables, which the .NET library uses quite a bit).
However, I cannot figure out how to work with the Hashtable objects from
VB6.
Here's an example. I have a .NET function called GetProjects() that returns
a Hashtable of Project objects. The Project object is one that we defined,
and has a variety of methods and properties. All I need for the moment is
the .Name property (which returns a string).
I'd like to get the Hashtable, and simply loop through the objects contained
therein, and display the Project.Name property for each.
I was thinking something along the lines of:
Dim aLibrary As New NETLibrary ' This is my .Net library that I'm trying
to call from VB6
Dim aHash As New Hashtable
Dim aProject As Project

Set aHash = aLibrary.GetProjects

For Each aProject in aHash
Debug.Print aProject.Name
Next
Unfortunately, VB6 isn't liking that "for each" syntax. But I'm at a loss to
figure out how to do this otherwise.
Can anyone offer suggestions?
Thanks!
Dec 5 '05 #1
2 3497
Scott,

I have no idea how to work with a .Net hashtable in VB6, or even if you can
work with a .Net hashtable in VB6.

However, I do know that you cannot loop through a hashtable like you are
attempting, even in .Net.

Remember, a hashtable holds a collection of DictionaryEntry objects. So in
..Net you would do something like this:

Dim aProject As Project
For each de As DictionaryEntry In aHash
aProject = de.Value
Msgbox aProject.Name
Next

Kerry Moorman

"Scott M. Lyon" wrote:
I'm working on using the COM Interop wrapper on an existing .NET library, to
allow existing VB6 applications to call the .NET code.
And I've been able to get it working in a basic sense (I can return basic
types like strings and booleans, and I've added a reference to MSCORLIB.tlb
so I can even return Hashtables, which the .NET library uses quite a bit).
However, I cannot figure out how to work with the Hashtable objects from
VB6.
Here's an example. I have a .NET function called GetProjects() that returns
a Hashtable of Project objects. The Project object is one that we defined,
and has a variety of methods and properties. All I need for the moment is
the .Name property (which returns a string).
I'd like to get the Hashtable, and simply loop through the objects contained
therein, and display the Project.Name property for each.
I was thinking something along the lines of:
Dim aLibrary As New NETLibrary ' This is my .Net library that I'm trying
to call from VB6
Dim aHash As New Hashtable
Dim aProject As Project

Set aHash = aLibrary.GetProjects

For Each aProject in aHash
Debug.Print aProject.Name
Next
Unfortunately, VB6 isn't liking that "for each" syntax. But I'm at a loss to
figure out how to do this otherwise.
Can anyone offer suggestions?
Thanks!

Dec 5 '05 #2

"Kerry Moorman" <Ke**********@discussions.microsoft.com> wrote in message
news:B2**********************************@microsof t.com...
Scott,

I have no idea how to work with a .Net hashtable in VB6, or even if you
can
work with a .Net hashtable in VB6.

However, I do know that you cannot loop through a hashtable like you are
attempting, even in .Net.

Remember, a hashtable holds a collection of DictionaryEntry objects. So in
.Net you would do something like this:

Dim aProject As Project
For each de As DictionaryEntry In aHash
aProject = de.Value
Msgbox aProject.Name
Next


I've actually found a few ways that I can loop through a hashtable in .NET.
The on you mentioned (using DictionaryEntry objects to do a FOR EACH)
doesn't apply to VB6 because you can't do a FOR EACH in VB6 except on
generic Variant or Object objects. And if I change it to a Variant (or
Object), then FOR EACH oVariant IN aHash fails.

The other ways I found was using either iEnumerator or iDictionaryEnumerator
(and the Hashtable's GetEnumerator function), and using the MoveNext
property of the enumerator to loop through the items.

Unfortunately, the iEnumerator (when exposed in VB6) while it allows me to
MoveNext through the enumerations, each one comes through as empty (despite
me verifying that the hashtable has data in it).

Just as unfortunately, the iDictionaryEnumerator won't even allow me to use
the .MoveNext method in VB6.
Anyone have any other ideas/suggestions?
Thanks!
Dec 9 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1291
by: name | last post by:
Tricky I'm trying to do the following string sString = "Here is a test string"; string sFieldRef = "sString"; MessageBox.Show(sFieldRef); //How do I get this line to display: Here is a...
5
2812
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
5
15562
by: Cyrus | last post by:
I have a question regarding synchronization across multiple threads for a Hashtable. Currently I have a Threadpool that is creating worker threads based on requests to read/write to a hashtable....
33
3285
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are...
16
696
by: Sreekanth | last post by:
Hello, Is there any better collection than HashTable in terms of performance, when the type of the key is integer? Regards, Sreekanth.
3
9680
by: Fred | last post by:
I'm trying to build a hashtable and a arraylist as object value I'm not able to retrieve stored object from the hashtable. Hashtable mp = new Hashtable(); // THE HASHTABLE ArrayList...
2
1544
by: Tamarack | last post by:
I have a simple function which loops through all the controls on a form searching for a specific one: Public Function FindControl(ByVal ctrls As Control.ControlCollection, ByVal ctrlName As...
7
2548
by: msdev | last post by:
Hello, I am creating my own webbrowser to learn VB .Net. I am stuck on an issue with regards to dynamically-created controls, in this case tabs on a tabcontrol and webbrowsers created within...
2
3137
by: PAzevedo | last post by:
I have this Hashtable of Hashtables, and I'm accessing this object from multiple threads, now the Hashtable object is thread safe for reading, but not for writing, so I lock the object every time I...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.