This is continuation . . .
Okay,
Hear it goes
Well my Aim is to Bring an excel stored data into QTP Environment.
I hope you remember this figure . . .
Well this is the Screenshot of "GlobalData.xls", I have explained why did I named this excel as GlobalData.xls
Let's give this excel file an importance because whenever you script is going to start with execution, this file will play major role in term of Initializing your per-requisite of your Test.
Notice the column names "Key" and "Value", what I gonna tell you now, I think I gotcha!!!
I shall extract this data from excel using ADODB, then store that data into Dictionary Object and then make that Dictionary object as Environment Variable.
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & getGlobalDataxlsPath() & ";Extended Properties=""Excel 8.0;HDR=Yes;"";"
objRecordset.Open "Select * FROM [SheetName$]", objConnection
Now Since you've got the RecordSet, now it's time for Dictionary Object to come into picture
Set objDict = CreateObject("Scripting.Dictionary")
Do Until objRecordset.EOF
objDict.Add objRecordset.Fields.Item("Key"), objRecordset.Fields.Item("Value")
objRecordset.MoveNext
Loop
Now let's make this Dictionary Object an Environment Variable.
Environment.Value("GlobalData") = objDict
From now on where ever you want you can use the Dictionary object stored in Environment, your reference code will be
strBasePath = Environment("GlobalData")("BasePath")
For more insight on referencing on Environment Variables click here
So folks,
I have shown you the code just for understanding the concept behind it, for codes google it out!!!
*getGlobalDataxlsPath()shall return the complete path of "GlobalData.xls" file, Since we need to achieve portability, the path shouldn't be the static one, I shall post later on the logic behind it.
Till Then Take Care . . .
Okay,
Hear it goes
Well my Aim is to Bring an excel stored data into QTP Environment.
I hope you remember this figure . . .
Well this is the Screenshot of "GlobalData.xls", I have explained why did I named this excel as GlobalData.xls
Let's give this excel file an importance because whenever you script is going to start with execution, this file will play major role in term of Initializing your per-requisite of your Test.
Notice the column names "Key" and "Value", what I gonna tell you now, I think I gotcha!!!
I shall extract this data from excel using ADODB, then store that data into Dictionary Object and then make that Dictionary object as Environment Variable.
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & getGlobalDataxlsPath() & ";Extended Properties=""Excel 8.0;HDR=Yes;"";"
objRecordset.Open "Select * FROM [SheetName$]", objConnection
Now Since you've got the RecordSet, now it's time for Dictionary Object to come into picture
Set objDict = CreateObject("Scripting.Dictionary")
Do Until objRecordset.EOF
objDict.Add objRecordset.Fields.Item("Key"), objRecordset.Fields.Item("Value")
objRecordset.MoveNext
Loop
Now let's make this Dictionary Object an Environment Variable.
Environment.Value("GlobalData") = objDict
From now on where ever you want you can use the Dictionary object stored in Environment, your reference code will be
strBasePath = Environment("GlobalData")("BasePath")
For more insight on referencing on Environment Variables click here
So folks,
I have shown you the code just for understanding the concept behind it, for codes google it out!!!
*getGlobalDataxlsPath()shall return the complete path of "GlobalData.xls" file, Since we need to achieve portability, the path shouldn't be the static one, I shall post later on the logic behind it.
Till Then Take Care . . .
-Pankaj Dhapola
Let's Think on it
Let's Think on it