My Blog List

Tuesday, November 27, 2012

Read, Write Excel - QTP, VbScript


Lot of members are facing some errors whenever trying to connect and read/write values from excel or other databases. Here is some code snippet which will easy the task for you...

To Get Data:
Function GetData(strFilePath, strSQL)
 Dim objConn, objRecord, strConnectionString
 Set objConn = CreateObject("ADODB.Connection")
 Set objRecord = CreateObject("ADODB.RecordSet")

 strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFilePath & ";Excel 12.0;HDR=YES;READONLY=1;IMEX=1;"

 objConn.Open strConnectionString
 objRecord.Open strSQL, objConn
 msgbox objRecord(0).Value
 objConn.Close
End Function

Points to take care:
1. Always use readonly=1 to force read-only mode while reading.
2.Use IMEX value based on your requirement.
IMEX=1 - It will convert all data types to text and return.
IMEX=2 - It will return the data as it is.

To Write Data:
Function UpdateData(strFilePath, strSQL)
 Dim objConn, strConnectionString
 Set objConn = CreateObject("ADODB.Connection")

 strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFilePath & ";Excel 12.0;HDR=YES;READONLY=0;IMEX=0;"

 objConn.Open strConnectionString
 objConn.Execute strSQL
 objConn.Close
End Function

Points to take care:
1. Always use readonly=0 to force read-only mode to OFF while writing.
2.Here IMEX=1 will restrict the write access. So you should not use IMEX property. Otherwise use IMEX=0.

Some common Errors:
1. Cannot find installable ISAM
if the corresponding version dll is not found, then this error will come.Sometimes this below will do trick. If you mentioned your connection string like,
Extended Properties=""Excel 12.0"", then remove it and simply mention "Excel 12.0" as version. Otherwsie mention the max version available/installed on your system.
2.Should be updatable Query
For writing data, if you ever used IMEX property as 1/2 - this error will come as it blocks the write access. Remove the IMEX part, otherwsie set as IMEX=0.
3. One or more required parameters are incorrect
If error contains term like one or more required parameters, then you should re-visit your query. Query should be the problem.

Wednesday, October 3, 2012

QTP - Get multi line data from Excel Cell

Today I am going to write a simple topic on excel and it seems very simple but lot of automation testers in need of this topic. Say I want to have multiple data on a single cell(using ALT+ENTER). This will solve the purpose as well as maintenance easy. 
Ok, How to get that data from excel and separate the data which was enterted using ALT+ENTER.
Just get the cell data and replace the string for vbLF with "" (Empty String) and you can pass your data.
Normally new line indicates vbCRLF (Chr(13) + Chr(10)) but in excel new line char is Char(10) i.e. only vbLF not vbCR or vbCRLF.

Hope this will help you guys !!!

Tuesday, September 11, 2012

QTP - Memory Usage and Others

Lot of guys will face app hanging problem while script execution in QTP. You can always use QTP provided SystemMonitor API to know memory usage by application an you can decide your control mechanisms.

SystemMonitor.GetValue("YourApp.exe","Memory Usage (in MB)")


In the same way, you can get processor usage, Os details, etc..
If this will give you exact thing, always you can use WMI to get every system information you need.

Sunday, August 26, 2012

QTP - Object Identification Types / Ways

In QTP, we can use lot of ways to identify an object. Most of the QTP Test Developers are always using streamlined and static approaches and if object is not identifiable using those approaches, just leaving then as not identifiable.
We can try using below ways of handling objects for our purpose before saying NO !!!

1. Store the objects in OR
If you are comfortable on using OR and suitable for your project with your designed framework, you can go ahead with OR.
a. Add the object in OR, then see what are the properties will make QTP to identify this object uniquely. 
b. Remove unwanted properties
c. Add unique and required properties
d. Assign regular expressions for the required properties which have dynamic values in full or part.Make use of Reg Exp Evaluator to set the RegExp correctly.
e. Assign a human understandable, easily classifiable logical name for the object based on type of object, application module or screen, etc.

2. Use Descriptive Programming
Here you can use 2 types of DP.
1. Inline or String DP:
Mention your properties in the line where we are mentioning our actions to be performed using name:=value pairs. 
Here the important point is, this type of object identification is regular expression support enabled by default. So you have to use literal character(\) if any regexp chars available as part of your name:=value pairs.
2.Description Object:
If you have lot of properties to instruct QTP to identify an object, inline DP will create lengthy statement and confusion. At this point, you can go with Description Object.
Create an instance of Description object and assign the values for all the required properties. Also you need to assign RegularExpression property true/false to enable the regexp support for the assigned properties.

3. Xpath
From QTP 11, you are ready to use xpath for web objects. Really its an easy way to inform the web objects path to QTP as like our normal DP.
Ex. To get the google search box
Browser("title:=.*google.*").Page("title:=.*google.*").WebEdit("xpath:=//INPUT[@name='q']").Set "testing"
Refer XPATH.

4. CSS Path
This also supported from QTP 11 like xpath.
Ex.To get the google search box
Browser("title:=.*google.*").Page("title:=.*google.*").WebEdit("css:=INPUT[name='q']").Set "testing"
Refer CSS Path.

5. DOM Path
This one you can use from previous versions of QTP. This is a method where we are directly fetching our objects from web page document using DOM.
In QTP, they have provided a function called RunScript and RunScriptFromFile for PAGE objects to execute the scripts on the page to get the objects.
You can make use of IE developer tools(press F12 to open in IE) to check and develop your DOM scripts.
Ex.To get the google search box
Browser("title:=.*google.*").Page("title:=.*google.*").RunScript("document.getElementsByName('q')(0)").value = "testing"
Refer QTP RunScript.

6. Virtual Objects
This is a known way to all QTP test developers. Just we are creating an image of our object and instructing QTP to identify runtime object based on the image.
Here you need to take extra care with respect to different environments, themes and also need to place the virtual objects folder to all QTP machines. 
This feature is used rarely by QTP developers worldwide but based on this type of image recognition, we have lot of automation tools in current world.

7. Virtual Relation Identifier
From QTP 11, we have an option to instruct QTP to identify the objects as manual testers are doing in real time by seeing visually using eyes. i.e. We can instruct QTP like,
a. Click the button which is available next to an identifiable button/element in horizonally.
b. Click the button which is available next to an identifiable button/element in vertically.
c. Click the button which is available before to an identifiable button/element in horizonally.
d. Click the button which is available before to an identifiable button/element in vertically.


You can instruct these properties in Object Repository itself for Visual Relation property.
Also, we can instruct this type of visual relation in programmatic way using Descriptive Programming without using Object Repository.

8. Create Custom Add-Ins
Create custom Add-Ins? What? Can we create add-ins ourself?
Yeah !!! QTP 11 provides an tool/utility called QTP Extensibility Accelerator to create custom add-ins for the custom objects support in your AUT.
Currently, QTP 11 provides a add-in creation template for Web Objects only. We can create our custom add-in with in 10 mins. But for other environments, you need to create using some IDE, need some basic VB or other coding knowledge. But we can create custom add-ins for all type of objects using this tool.
We will see a separate topic for this add-in creation later here.

Sunday, August 19, 2012

QTP - Common error messages

Always I am seeing  many of my friends asking for help if any error occurs while running script in QTP without googling for help. How much troubleshooting you guys are doing will directly reflect your knowledge on the tool. I agree, no one knows each and every error occurs in the software. But we can improve our knowledge by googling and doing workarounds...
Whenever the question "How much level you know QTP?" arrows me, always I am comfortable with the answer "below 10%". But after answered, my mind will have an inner thought like, What are the things I have to learn to fulfill the answer I have told because I never used lot of features in QTP.

Here I am listing out some of the errors, situations and what might be the original issue things etc. I hope this will give you some ideas to improve your debug ability and to solve your errors. Kindly correct me If I am wrong in any point.

Type mismatch:
- Mostly doing operations with different data types without doing type conversions
- Whenever the mentioned object or function not available in the code with respect to QTP knowledge. You might forgot to associate the function lib or renamed of the function.

Parameter is Incorrect:
- The data to be inserted or set in the object will have extra length. i.e. above the design limit of the test object.
Ex. Mostly while setting some value in edit box, we will get this error because we are trying to set the value with 50 chars in the edit box designed to handle max 30 chars.

UnExpected ):  
- Mostly fresh QTP coders will see this error. Whenever trying to call a function, use parenthesis only if you are going to get the returned value from the called function. 
- If you are not going to get the return value, then just mention your parameters without using ().

No. of parameters mismatch:
- Here you could have missed to mention all the parameters for your function.

More than 1 object is matching...:
- Here QTP identifies more than 1 object with the mentioned properties and got confused which one to handle. You need to give additional properties to identify your object uniquely. Sometimes index will give you hand.

Out of bound error:
- When you are trying to get the values from an array position which is not declared or assigned or not available.

Name undefined:
- You should have mentioned Option Explicit to force the variant declaration but you forgot to add the declaration for the variant.

Name redefined:
You should have mentioned Option Explicit to force the variant declaration but you declared the variant which is already declared.

Object Required:
Sometimes we will try to get an object from long hierarchy if its not identifiable easily. At this time, if any mid way object is failed in identification, QTP will throw this error.
Ex. While trying to get the object inside the WebTable, QTP will throw this error if webtable itself not identified.

General Run Error:
- Say you have function in your vbs file like Function abc(a,b) and from your test you are trying to call like If abc(a) Then. Here QTP will raise this type of error.
- And also some places where QTP not able to identify which type of error.

I will keep adding the errors I have faced and known to my knowledge. Definitely every one will face lot of errors. Kindly share the same here so that I will add those too for every one's reference.

Wednesday, July 25, 2012

Common QTP Topics/Questions

Here I am listing out some common QTP topics those are concentrated on most QTP interviews. Hope this will help lot of QTP beginners.

1. Why we go for automation?
2. What is Action? What are the types?
3. What is function? What is Sub? Diff between these two?
4. What is OR? Types of OR?
5. Which kind of OR is best?
6. What is TO? What is RO?
7. How QTP identifies object in UI and does the operations?
8. What are types of properties for a object? Mandatory, Assistive, Ordinal Identifiers.
9. What is smart Identification?
10.What is Synchronization? What are the synchronization methods available?
11.How you generated your results?
12.How you will email the results automatically after execution?
13.What is framework? Have you worked/designed a framework?
14.VBScript - String functions, Array, FileSystemObject, DictionaryObject
15.Connecting Excel and fetching data?
16.Connecting database and fetching data?
17.What kind of applications you have automated?
18.What kind of controls you automated? Native Controls, Thir party controls, etc..
19.What is DP? Why we go for DP? What are DP approaches?
20.Write a script for this scenario using DP?
21.How you handled error recovery?
22.Framework - Driver Script, TestData, Config Files, OR files, Reusable function Librarty
23.Tell me some re-usable components you have written?
24.What is environment variables? What is the purpose? How you will get/set value?
25.What is AOM - Automation Object Model? How to use this?
26.Have you worked in batch run?
27.Have you integrated QC with QTP and executed script from QC?
28.What are the type of files under each action and test? What are the extensions?
29.What is DataTable? How to use that?
30.What is Option Explicit? Why we are using this?
31.Regular expressions?
32.Checkpoints and its usage? types?
32.etc...

Monday, July 23, 2012

Agile Model - SCRUM Process Overview

Lot of testers have interest to know about,
1. What is agile model?
2. What is the advantage of it over other models?


Agile - Simply we can say "On demand, more monitored and controlled testing"
Agile model have benefits like,
1. Easy adoption of requirement changes at any stage.
2. Piece of working product will be arrived very early in life cycle.
3. More monitoring on team so every team members will be in same path and goal.


SCRUM is one of a process of agile methodology. SCRUM involves below terms,
1. Sprint
2. Scrum master
3. User Stories
4. Work Items
5. Sprint Back Logs
6. Sprint retrospective item, etc.


Sprint - Sprint is nothing but the scrum period. i.e. The no of days for between each release like 30 days, 15 days. This is mainly based on customer requirement. If your every sprint consists 30 days, then every 30 days there will be a release. Sometimes release will not be there based on customer request.


Scrum Master - The person responsible to assign the tasks to team members and monitor the team.


User Stories - User Stories are the original requirements from customer. This may be "New functionality" or "Change Request".


Sprint Work Items - Work Items are the Task items created by Scrum Master with Estimated time for each User story. Normally scrum master will create task item for each user story and assign it to some team member with estimated time.


Sprint BackLog Item - Sprint back log items are the sub task items created by every team member for each assigned work item. Team member will create this sprint back log item for each assigned work item and he will set estimated time. This is used to track the daily effort done by team member and to update the status like how much hrs actually worked on this sprint back log item. Automatically this will affect the Work Item related to this Sprint back log item. So finally the User story will be finished by doing all the work items related to that user story.


Sprint Retrospective Item - Retrospective item will be created after sprint release. This should cover the answers for below 2 questions.
1. What went well?
2. What can be Improved?


Now, you should be aware of above terms. Let's see, how actually scrum will be followed in real time projects.
1. Customers will enter the User Stories in your ALM system like TFS, QC, etc.
2. Once received user stories, scrum master will arrange a meeting called Sprint Planning Meeting
3. In Sprint planning meeting, scrum master will discuss with team members like
    What are the user stories we can select for this sprint?,
    Which user story going to handle every team member?, etc.
4. After planning meeting, scrum master will create Sprint Work Items for each user story and assign them to team members. For ex. Login Module is the user story. For this story, scrum master will create work items like Development of Login Module, Testing of Login Module, Regression and Retesting of Login module, etc. and he/she will put the estimated time to finish each work item.
5. Now, team members will pick up their work item and create Sprint Back Log Items i.e. sub work items. For ex. Team member will create sprint back log items like UI development, functionality development, unit testing, etc for Development of Login module work item.
6. Daily team members will work on their tasks and update their actual worked hours (i.e. burning worked hours) against estimated hours in sprint back log items.
7. This will give progress status for every sprint back log item which in-turn update sprint work item's progress. Finally every one can able to know the progress status of each user story.
8. Daily 10 to 15 mins quick meeting will be arranged by scrum master to update daily status, showstoppers and any blockings to continue the planned tasks. Based on this, they will continue their progress. This is called Daliy Scrum Meeting
8. Once everything is OK and working fine and tested, then we will go for release.
9.After the release, scrum master will arrange a meeting called Sprint Retrospective Meeting. In this meeting, every will discuss about the 2 points mentioned above and will create retrospective items if any.
10. In future releases, team members will concentrate to cover the created retrospective items as part of sprint tasks.


Hope this will give you basic idea about the scrum process in agile model...

Friday, July 20, 2012

What is Framework?

Today, I am going to discuss about framework due to request of my friend Anand.


Lot of QTP guys know the information on How to Create Test, How to identify Complex objects, How to generate results and etc. But still somebody have doubts like
What is Framework?
Why we need Framework?
What's the purpose of it?
How to design framework?
Is that required lot of coding knowledge?, etc.


Let's consider a case. We have 100 test scenarios to automate. Each test scenario have around 100 test cases. Here you will do the following....
Design:
1. Create Test Scripts for each case by creating separate actions.
2. Each test case script i.e. each action will have associated resources. - Object Repository, Function Library and Recovery Scenario files.
Execution:
1. You will have own driver script.
2. This will call each action one by one.
Maintenance:
1. If any UI changes happened, you need to find the particular OR file to update the same.
2. You need to maintain lot of OR files which is a tough task.
3. If any new resource joined in Team, its tough task to give KT and to get on track.


So, you have lot of drawbacks in your script generation, execution and mainly on Maintenance phase. This will not give estimated ROI for clients. So,
1. How to reduce these complexities?
2. How to make our task easy?


Here we go...
Framework - Framing our work. How we are framing our automation work i.e. Script Design, execution and maintenance of our automation project which will yield good results on below points.
1. Easy script generation.
2. Maximum Re-Usability.
3. Low maintenance cost.
4. Easier execution of scripts for every new builds based on our decisions.
5. Ability to design test scripts using Non-Technical testers, Business Analysts, etc.


Let's design a sample framework for QTP for the same case we talked above.
Framework Design:
1. Let's create some folder structure which will help us to keep our files in respective folder. This will help a lot while our project grows.
2. Create a folder "MyApp-Automation" - Under this folder,
       Create a folder "Function Library" - Under this, maintain all our function libraries like .vbs, .qfl    and .txt files.
       Create a folder "Object Repository" - Under this, maintain OR files. Create a Shared OR for different modules or Create a Shared OR for each application.
       Create a folder "Data Files" - Under this, maintain all test data excel files, Scenario files, Test Cases files, etc.
       Create a folder "Config Files" - Under this, maintain all configuration files whether in .ini or .xls format. Maintain all the data required globally for execution of any test in these files so that we can read and set these values as Environment Parameters to access through out our execution scope.
       Create a folder "Results" - Under this, export our results after execution by creating a subfolder with name as "MyTest_CurrentDate_Time".
Test Design:
1. First identify the available functionalities, test cases and flow of business. Based on your analysis, design some re-usable functions like Login, CreateTxn, DeleteTxn, Logout, etc.
2. Then go and create Test Case Script. Here just you can use all your re-usable functions already written. No need to write again and again code for same functionality. This will reduce your script design time as well as maintenance time.
Execution:
1. Add a field "Execute?" in your TestScenarios file and mark as "Yes/No" based on your execution requirement.
2. The same way, add this field for TestCases sheet and mark as Yes/No.
3. Now design your DriverScript like,
   a) Read the Test Scenarios file.
   b) Check Execute field. If Yes, goto TestCases file for this TestScenario.
   c) Read TestCases. If Yes, execute this case. i.e. Call the function for this case like "Call TS1_Case_001". Here Case_001 is the function for your TestCase TS1_Case_001.
   d) The same way, it will loop for all cases under the Test Scenario and then will pickup and loop for all Test Scenarios.
4. So, the only initial point is your Driver Script after setting up your requirement for execution and test data.
Maintenance:
1. Here you have minimum number of OR files based on application or modules. So if any UI changes happened in application, its easy to find and update values.
2. Also, if any functionality is changed in your application, just go and modify in your re-usable function. That's enough, it will affect all the cases as the re-usable function only called inside all the cases. No need to open each case and modify.
3. Even manual testers or business analysts can design test script because we have ready made functions for all functionality. Only thing they should know, purpose and use of each re-usable function which we can deliver by creating a documentation.


Types:-
For the types of frameworks, you will find lot of resources in web. Just Google it. Just providing the main types available.
1. Keyword-Driven
Our designed re-usable functions are Keywords.
2. Data-Driven
Your test data is driving your test. i.e. Your single test will run multiple times with different data each time.
3. Hybrid
Any combinations for more than one kind of framework.


So, I hope now you might have some idea about framework and you might be in the position to answer all the questions I have listed on top.
Why are waiting? Start creating your framework now !!!


Here are some links:-
http://www.youtube.com/watch?v=XGr5HC8VrAI
http://www.youtube.com/watch?v=rB3r7Dp_jyM

Saturday, May 19, 2012

Download File - VBScript function

Here is the function to download any file over internet using XMLHTTP COM objects in VBScript. 

  1. Function Download(sFileURL, sLocation)
  2.   'create xmlhttp object
  3.   Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
  4.  
  5.   'get the remote file
  6.   objXMLHTTP.open "GET", sFileURL, false
  7.  
  8.   'send the request
  9.   objXMLHTTP.send()
  10.  
  11.   'wait until the data has downloaded successfully
  12.   do until objXMLHTTP.Status = 200 :  wscript.sleep(1000) :  loop
  13.  
  14.   'if the data has downloaded sucessfully
  15.   If objXMLHTTP.Status = 200 Then
  16.  
  17.         'create binary stream object
  18.     Set objADOStream = CreateObject("ADODB.Stream")
  19.     objADOStream.Open
  20.  
  21.           'adTypeBinary
  22.     objADOStream.Type = 1
  23.     objADOStream.Write objXMLHTTP.ResponseBody
  24.  
  25.           'Set the stream position to the start
  26.     objADOStream.Position = 0    
  27.  
  28.           'create file system object to allow the script to check for an existing file
  29.           Set objFSO = Createobject("Scripting.FileSystemObject")
  30.  
  31.           'check if the file exists, if it exists then delete it
  32.     If objFSO.Fileexists(sLocation) Then objFSO.DeleteFile sLocation
  33.  
  34.           'destroy file system object
  35.     Set objFSO = Nothing
  36.  
  37.           'save the ado stream to a file
  38.     objADOStream.SaveToFile sLocation
  39.  
  40.           'close the ado stream
  41.     objADOStream.Close
  42.  
  43.     'destroy the ado stream object
  44.     Set objADOStream = Nothing
  45.  
  46.   'end object downloaded successfully
  47.   End if
  48.  
  49.   'destroy xml http object
  50.   Set objXMLHTTP = Nothing
  51. End Function
  52.  
  53. 'Call like this
  54. Download "http://tamilmp3world.com/123.mp3""C:\test1.mp3"

I got this script from internet and thanks for the author as I forgot where I took this.

ExecuteGlobal in VBScript

Most of guys will face this problem like,
- Having a class in a .vbs file say class1.vbs
- In another .vbs file, trying to create object for that class
Here it will say class is undefined because your class should be in global namespace so that your second script should know. To achieve this, use ExecuteGlobal command in VBScript.
Here I am putting sample function to include your class or other .vbs files which you are going to refer.
  1. 'To include a file which are referenced here.
  2. Sub Include(file)
  3.   Dim fso, f
  4.   Set fso = CreateObject("Scripting.FileSystemObject")
  5.   Set f = fso.OpenTextFile(file, 1)
  6.   str = f.ReadAll
  7.   f.Close
  8.   ExecuteGlobal str
  9. End Sub
  10. 'Just call this function like this in your scripts
  11. Call Include("C:\class1.vbs")
  12. 'Then try to create object for the above class
  13. Dim obj
  14. Set obj = New Class1
  15. 'continue...
Hope this give you ideas !!!

Saturday, May 12, 2012

Start learning VBScript or JavaScript

Lot of guys who are interested to move to automation testing from manual have dilemmas on how to start learning the scripting language, which one I have to install, where to study, etc.
For those who are covered under the above case, this article is for you.
Both VBScript and JavaScript will run on windows based script host. So follow the simple steps to learn.


1. Just create a text file in your system and save it as .vbs(VBScript) or .js(JavaScript) extension.
2. Open the .vbs or .js file using notepad or other your favorite notepad editor like wordpad, notepad++, etc.
3. Just do your code and save.
4. Just double-click the .vbs or .js file. It will execute and give you results.
5. For your understanding like what value it returns, use msgbox which will show the value in dialog while executing for VBScript. For JavaScript, just create an object for "WScript.Shell" and use Popup.
6. If errors in your code, the it will give you error dialog by specifying error line and other info.
For technical resources, browse google. You will get lot of sites which will teach you VBscript and JavaScript. Start from W3Schools as a beginner.
Here is another good link for VBScript here.
Just refer the sample code here.


Environment Setup:
Basically VBScript will support by default in all windows versions. First right-click the file, Properties and change the open with as "Cwindows\systems32\WScript.exe".
If you have problems in executing VBScript just follow the steps mentioned here.
Use this registry file to merge. Download here
For JavaScript, just assign open with as "Windows based script host" which mentioned above. If still facing problems, do merging these attached registry entries. 
Download for Windows 7
Download for XP

VBScript Dictionary Object vs JavaScript Object

In test automation world, always we have situations to return more than one value from a function call. For this we have some simple ways but yet always we searching for better ways. Here I am listing some ways we can 
consider.
1. Array
We have simple array concept in all languages but this not effective while retrieving values for a particular field because array is related to index. We can't know at which index which value is there. We have to implement our own methods to find them.
2. Class and Objects
This is an another effective method but the user need some information about classes and objects. You can create a class, then class variables for all fields you are going to return values. So just create an instance for this class i.e. object and assign the values for all properties associated with this object and return this object.
Here you can directly get your particular field value by passing the field name. No concept of indexes like array. So simple to access a value and assign a value.
3. Dictionary Object
This is mostly used format of returning multiple values in VBScript. This is an object which contains values in  key-value pairs format. Very simple to access, assign, remove, etc.
Here I am going to give some demo about VBScript Dictionary object.
  1. Dim dic
  2. Set dic = CreateObject("Scripting.Dictionary")
  3. dic.Add "Name""Shanmugavel"
  4. dic.Add "Age""26"
  5. dic.Add "City""CBE"
  6. dic.Add "Height""5.4"
  7. 'To Check a particular key exists or not
  8. If dic.Exists("Weight") Then
  9.    msgbox "Exists"
  10. Else
  11.    msgbox "Not Exists"
  12. End If
  13. 'To loop through all keys present in dic object
  14. For Each key in dic
  15.    msgbox dic.Item(key)  'Here we are using property "Item" to get a key value
  16. Next
  17. 'To change a key name without altering the value associated to that key
  18. dic.Key("Age") = "MyAge"
  19. msgbox "Value for MyAge: " + dic.Item("MyAge")
  20. msgbox "Check for Age Exists: " + CStr( dic.Exists("Age") )
  21. 'To get count of available Key-Value pairs
  22. msgbox dic.Count
  23. 'To get all key names only
  24. Dim KeyNames
  25. KeyNames = dic.Keys   'Returns an array
  26. For Each key in KeyNames
  27.    msgbox key
  28. Next
  29. 'To get all key values only
  30. Dim KeyValues
  31. KeyValues = dic.Items   'Returns an array
  32. For Each value in KeyValues
  33.    msgbox value
  34. Next
  35. 'To Remove a key-Value pair
  36. msgbox "Before Removing a key-Value pair, Count: " + CStr( dic.Count )
  37. dic.Remove("Height")
  38. msgbox "After Removing a key-Value pair, Count: " + CStr( dic.Count )
  39. 'To Remove all key-Value pairs
  40. dic.RemoveAll
  41. msgbox "After Removing all key-Value pairs, Count: " + CStr( dic.Count )
  42. 'To make key names Case-Sensitive
  43. ' -- By default, VBScript considers everything as Case-Insensitive because its a Case-Insensitive scripting language.
  44. ' -- We can make Case-Sensitive keys to have 2 keys with same key name i.e. One with lower case and another with upper case
  45. ' -- VBBinaryCompare - 0; VBTextCompare - 1; VBDataBaseCompare - 2 (compares information inside)
  46. dic.CompareMode = VBBinaryCompare  'or assign value 0
  47. dic.Add "Name""shanmugavel c"
  48. dic.Add "NAME""SHANMUGAVEL C"
  49. msgbox "Name: " + dic.Item("Name")
  50. msgbox "NAME: " + dic.Item("NAME")

JavaScript:
In JavaScript also we have first 2 options as in VBScript. But JavaScript have a concept called associative array or Object i.e. equivalent to Dictionary Object in VBScript. Here I am giving simple demo code.
  1. var WS = new ActiveXObject("WScript.Shell");
  2.   //Declaring and Assigning values with key-value pairs
  3.   var obj = { Name: "ShanmugavelC", Age: "26",
  4.               City: "CBE", Height: "5.4"       };
  5.   //To get all key-value pairs
  6.   for (key in obj)    
  7.     WS.Popup("Value for " + key + ": " + obj[key]);
  8.    
  9.   //To add a Key-value pair
  10.   obj["Weight"] = "69";
  11.   //To check a key exists or not
  12.   if( obj.hasOwnProperty("State") )
  13.     WS.Popup("Key State Exists");
  14.   else
  15.     WS.Popup("Key State not Exists");
  16.   //By default, JavaScript is Case-Sensitive
  17.   obj["NAME"] = "SHANMUGAVEL C"
  18.   WS.Popup( "Value for NAME: " + obj["NAME"] );
  19.   WS.Popup( "Value for Name: " + obj["Name"] );
Hope this will give you some ideas !!!