Jump to content

Recommended Posts

Posted

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?

Posted

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.

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
×
×
  • Create New...