Rahul:

In part, I am going to cheat and refer to the following two articles.

VB6 Collection, VBScript Dictionary, and VB.NET Hashtable
http://visualbasic.about.com/od/usingvbnet/l/aa070903a.htm
http://visualbasic.about.com/od/usingvbnet/l/aa071203a.htm

In terms of speed, within QTP, I cannot picture having more than a few
hundred key/value pairs so the difference in speed would not be
important.

What I really like about the .net hashtable and dictionary objects is
the use of contains. We can easily find if a value exists by using
myHash.ContainsValue("looking for this value").  Much nicer/quicker
than creating the valueArray and then searching the array or creating
other code to check for existence.

There is the problem with vbscript dictionary of accidentally creating
a key with a value of null.  A while back, I ran across an article
that discussed some of the problems with the vbscript dictionary but I
cannot seem to find the article at the moment.

There are several different types of .net dictionaries depending upon needs.
http://stackoverflow.com/questions/301371/why-is-dictionary-preferred-over-hashtable
 (item  55 lists five types).

To deviate from the question, I expect the ArrayList will be the main
.NET item I will use.  The array list allows insertion at a specified
position, removal of an item, sorting.  All this without writing
additional functions. The only problem with the sort is - it is not
numerical.  http://www.learnqtp.com/dotnetfactory-qtp-part7-arraylist/
does a beautiful job of demonstrating its methods.

hth,


Parke

On 7/31/12, iRahulSingh <[email protected]> wrote:
> Nice Info Parke ... thanx for sharing.
>
> Would like to ask if you can share your thoughts,  would there be any
> specific benefits/advantage of using "System.Collections.Hashtable" over
> existing Dictionary objects may be in terms of memory saving or execution
> time ??
>
>
> Cheers..
> Rahul
>
> On Monday, July 30, 2012 8:11:12 PM UTC+5:30, Parke wrote:
>
>> We can use the hashtable from .Net within QTP and list the keys and
>> values
>>
>> Set myHash =
>> DotnetFactory.CreateInstance("System.Collections.Hashtable")
>> Set myEnumerator =
>> DotnetFactory.CreateInstance("System.Collections.IDictionaryEnumerator")
>>
>> myHash.add  "a", "apple"
>> myHash.add "o", "orange"
>> myHash.add  "r","red"
>> myHash.add "b", "blue"
>>
>> Set myEnumerator = myHash.getEnumerator
>>
>> ' using contains returns true or false
>> print "contains B " & myHash.Contains("B")
>> print "contains b " & myHash.Contains("b")
>> print "hash contains value red " & myHash.ContainsValue("red")
>> print "value for o = " & myHash.Item("o")
>> print "number of keys = " & myHash.count
>>
>> While myEnumerator.movenext
>>         print "key " & myEnumerator.Key & ":: value " & myenumerator.value
>>
>> Wend
>>
>> Have fun playing with it.
>>
>>
>> Parke
>>
>
> --
> You received this message because you are subscribed to the Google
> "QTP - HP Quick Test Professional - Automated Software Testing"
> group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/MercuryQTP?hl=en
>


-- 
Parke
Cell: 770-842-0121

-- 
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en

Reply via email to