Jump to content
Sign in to follow this  
Skullman

Hash table problem iterating it

Recommended Posts

Skullman

I am trying to iterate a Hash table that I've created (Local $things = ObjCreate("System.Collections.Hashtable"))

And of course I've added some elements successfully: ($things.add($test, $test))

When I use things.count and display the value it tells me that it contains 9 elements so adding works and retrieving works also fine when I type in the a key.

The documentation says that I can iterate a collection like this by using:

FOR $element IN $things

<mycode>

NEXT

But this block is never executed when I am using these statements and and I am wonderwing why. What am I doing wrong here?

Share this post


Link to post
Share on other sites
Authenticity

Don't know how to get the enumerable's GetEnumerator() method but you can do it like this:

Dim $oObj = ObjCreate('System.Collections.Hashtable')

For $i = 1 To 10
    $oObj.Add('Key' & $i, 'Value ' & $i)
Next

For $i = 1 To 10
    ConsoleWrite($oObj('Key' & $i) & @CRLF)
Next

Share this post


Link to post
Share on other sites
Skullman

Don't know how to get the enumerable's GetEnumerator() method but you can do it like this:

Dim $oObj = ObjCreate('System.Collections.Hashtable')

For $i = 1 To 10
    $oObj.Add('Key' & $i, 'Value ' & $i)
Next

For $i = 1 To 10
    ConsoleWrite($oObj('Key' & $i) & @CRLF)
Next

Sure, but when I use this I loose some of the advantages that maps have over arrays. A way to iterate the keys (without restricting them to be built like that) would be much better.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.