Retrieving data from Txt file into datatable
Retrieving data from Txt file into datatable
- Code:
Public Function ReadLineTextFile (strTextFile)
Dim fso, MyFile
Dim arrPairs, arrColumns, i
Set fso = CreateObject("Scripting.FileSystemObject")
' Open the file for reading only
Set MyFile = fso.OpenTextFile(strTextFile, 1)
' Read the input file
ReadLineTextFile = MyFile.ReadLine
' Load the Global DataSheet.
arrPairs = Split(ReadLineTextFile, "|")
' Note: This loop begins at Index 3 because Indices 0, 1, and 2
' (CurrentURL, CurrentBrowser, and CurrentPage) are already
' in the Global DataSheet)
For i = 3 To UBound(arrPairs) - 1
arrColumns = Split(arrPairs(i), ";")
DataTable.GlobalSheet.AddParameter arrColumns(0), ""
DataTable.Value(arrColumns(0), dtGlobalSheet) = arrColumns(1)
Next
End Function ' ReadLineTextFile (strTextFile)
In your test script, just identify the path and filename of the text file...
' Identify the name of the input file to use.
strTextFilePath = "C:\Test Data Files\"
strTextFile = strTextFilePath & "FileName.txt"
Then just call the function when you need to...
Call ReadLineTextFile (strTextFile)
thomasdfg- Posts : 11
Join date : 2014-06-18
Age : 39
Location : Hyderabad
Similar topics
» How to add or delete columns to a QTP datatable sheet
» How to Download a file from Quality Center (QC/ ALM) to local machine
» How to Download a file from Quality Center (QC/ ALM) to local machine
Permissions in this forum:
You cannot reply to topics in this forum
Thu Jun 19, 2014 11:31 am by thomasdfg
» How to identify the object when it is dynamically changing behavior
Wed Jun 18, 2014 6:37 pm by thomasdfg
» Patches for QTP 10, 11, 11.5
Wed Jun 18, 2014 6:04 pm by thomasdfg
» Retrieving data from Txt file into datatable
Wed Jun 18, 2014 5:32 pm by thomasdfg
» VB Script to count number of links in a web page.
Wed Jun 18, 2014 4:51 pm by thomasdfg
» Customized HTML reports in QTP
Wed Jun 18, 2014 4:42 pm by thomasdfg
» how to print values into a field of a web page, from a data table in qtp?
Wed Jun 18, 2014 4:37 pm by thomasdfg
» How to delete cookies using QTP?
Wed Jun 18, 2014 4:30 pm by thomasdfg
» When UFT Does Not Identify an Object
Wed Jun 18, 2014 4:23 pm by thomasdfg