Re: Nested Dictionary Objects : I'm confused :(

402 views
Skip to first unread message

Rahul Singh

unread,
May 18, 2012, 7:47:54 AM5/18/12
to QTP - HP Quick Test Professional - Automated Software Testing
Hi Guyzz... 

Sorry for spamming, but this [ same code with a bit manipulation ] worked ..... 


Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")

d2.Add 1,2.1
d2.Add 2,2.2
d1.Add 3,d2
Set d2 = nothing
Set d2 = CreateObject("scripting.dictionary")
d2.Add 1,2.1
d2.Add 2,2.2
d1.Add 4,d2
Set d2 = nothing

msgbox d2.Count
msgbox d1.Count

For each i in d1
Set temp = d1(i)
For each c in temp
msgbox temp(c)
Next
Set temp = nothing
Next

Set d1 = nothing

I've done a mistake and few things I was ignorant abt got cleared from this :D

Cheers ...


iRahulSingh

unread,
May 18, 2012, 7:06:56 AM5/18/12
to QTP - HP Quick Test Professional - Automated Software Testing
Hey Guyz,

just wondering does nesting in dictionary objects exists in
Vbscripting or not [ hope it exists else my half day work will go in
vain :( ]
try this :


Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")

d2.Add 1,2.1
d2.Add 2,2.2
d1.Add 1,d1
d2.RemoveAll
d2.Add 1,2.1
d2.Add 2,2.2
d1.Add 2,d1
d2.RemoveAll

msgbox d1.Count

For each i in d1
Set temp = d1(i)
For each c in temp
msgbox temp(c)
Next
Set temp = nothing
Next

Set d1 = nothing
Set d2 = nothing


PS : Hope i havn't done anything wrong but somehow dictionary present
inside other dictionary is pointing to itself and not to the value
stored. i.e. d2 which is present inside d1 should point to values
stored inside it i.e. 2.1, 2.2 etc but bullshit it's not :(

PPS : Also, can we check the Memory location address in Vb Scripting
so as to check what's going on ???


Cheers ...

Abhijeet

unread,
May 20, 2012, 2:36:02 PM5/20/12
to mercu...@googlegroups.com
I'm pretty sure that's not the right way to use dictionary object. You need to use only strings or arrays as items in the dictionary.

-Abhijeet

bhavin v patel

unread,
May 20, 2012, 7:32:08 PM5/20/12
to QTP - HP Quick Test Professional - Automated Software Testing
As per I know, What you are trying to do is NODE in linked list mostly
used in java and C#. and as Abhijeet mentioned dictionary objects only
allow string and numbers.

However best thing is try to create dummy code and run above section.
If I get a time tomorrow, I will try to run it on my end also and lets
see what happens.. i am sure there are vbscript guru may suggest
complete out of box solution to over come this if nested dictionary
objects is not a solution.

I like your creation there and would like to see if dictionary objects
can be nested which will be really help full thing to know...

iRahulSingh

unread,
May 21, 2012, 11:05:39 PM5/21/12
to QTP - HP Quick Test Professional - Automated Software Testing

Hi Bhaavin & Abhijeet,

Nested dictionary is norm and can be achieved easily (as u can refer
the sample code in the past )
yes, it becomes quite useful working with them and helps a lott if you
have tons of info to store and process

do let the grp know in case you encounter any difficulty...even your
experiences.

cheers...

Parke Kuntz

unread,
May 22, 2012, 9:20:52 AM5/22/12
to mercu...@googlegroups.com
Bhaavin & Abhijeet:

Take a look at the url:
http://www.advancedqtp.com/complex-dictionary-usage/ for an example of
using nested dictionaries in QTP.

In the example below, I put arrays into nested dictionaries. The
initial key is unique.

option explicit

' arrays
dim arr1, arr2, arr3, arr4

' dictionaries
dim dic
Set dic = CreateObject("Scripting.Dictionary")
arr1 = array("1", "a2", "a3", "a4")
arr2 = array("2", "b2", "b3", "b4")
arr3 = array("3", "c2", "c3", "c4")
arr4 = array("4", "d2", "d3", "d4")

call array2dictionary (arr1)
call array2dictionary (arr2)
call array2dictionary (arr3)
call array2dictionary (arr4)

sub array2dictionary (arrName)
dim i
dic.Add arrName(0), CreateObject("Scripting.Dictionary")
dic(arrName(0)).Add "col2", arrName(1)
dic(arrName(0)).add "col3", arrName(2)
dic(arrName(0)).add "col4", arrName(3)
end sub

msgbox "Row 1, col 3 = " & dic("1").Item("col3")
msgbox "Row 4, col 2 = " & dic("4").Item("col2")
msgbox "Row 3, col 4 = " & dic("3").Item("col4")

msgbox "Finished"

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 Mercu...@googlegroups.com
> To unsubscribe from this group, send email to
> MercuryQTP+...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/MercuryQTP?hl=en
>


--
Parke
Cell: 770-842-0121

sachin mahajan

unread,
May 22, 2012, 12:45:35 PM5/22/12
to mercu...@googlegroups.com
Hi all..

I'm trying an automation on ACtiveX cntrls..but not geeting it ..

as syntax is Window("text:=Flight Reservation").ActiveX("acx_name:=MaskEdBox").SetTOProperty "text",062612


Plz let me know if i missed anything.

iRahulSingh

unread,
May 22, 2012, 1:29:23 PM5/22/12
to QTP - HP Quick Test Professional - Automated Software Testing
Hi Parke,

Nice Example though i'm not able to understand one line out of your
code :

dic.Add arrName(0), CreateObject("Scripting.Dictionary")

When the dictionary is not defined yet, can we do do as what you have
written or i'm not able to interpret correctly ??
and again can be seen easily, nested dictionary can handle so much
information and that too without much headache :)

Cheers ..

On May 22, 6:20 pm, Parke Kuntz <parke.ku...@gmail.com> wrote:
> Bhaavin & Abhijeet:
>
> Take a look at the url:http://www.advancedqtp.com/complex-dictionary-usage/for an example of

Parke Kuntz

unread,
May 22, 2012, 8:09:24 PM5/22/12
to mercu...@googlegroups.com
Rahul:

We are essentially adding a separate column / key, value in the subroutine for every column of the array.  Picture the arrays as a matrix or spreadsheet.

         col1   col1   col3   col4
row1   1        a2     a3      a4
row2    2       b2     b3      b4
row3   3        c2     c3      c4
row4   4        d2     d3      d4

Col1 goes into the initial dictionary and the other columns go into the second dictionary.

Look at

http://www.advancedqtp.com/complex-dictionary-usage/

Hopefully the above URL can make it clearer than I am able.

Parke

Abhijeet

unread,
May 22, 2012, 11:35:34 PM5/22/12
to mercu...@googlegroups.com
That's wonderfully fantastic. I must admit I never thought of this usage of dictionary object. It's a great learning for me.

Parke : I am a regular at AdvancedQTP but still I missed that post. It's a beautiful code.

Many thanks to Parke for your post and Rahul for bringing this question up!! 

-Abhijeet
Reply all
Reply to author
Forward
0 new messages