Micro Focus QTP (UFT) Forums
Read text from text file and save it into a variable in qtp - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Read text from text file and save it into a variable in qtp (/Thread-Read-text-from-text-file-and-save-it-into-a-variable-in-qtp)



Read text from text file and save it into a variable in qtp - arpan - 06-19-2013

Hi Guys,

I've a text file(data) which has 3 lines as following:

ABC
DEF
XYZ

I'm reading the text file using the following command:
Code:
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
    s1="C:\temp\data.txt"
   Set theFile = fso.OpenTextFile(s1, ForReading, False)
   Do While theFile.AtEndOfLine <> True
      retstring = theFile.ReadLine
      msgbox retstring
      Loop
   theFile.Close

Now, i want to store the 3 values from text file into 3 variables in qtp.
For example,
V1=ABC
V2=DEF
V3=XYZ

Can somebody please help me out??


RE: Read text from text file and save it into a variable in qtp - ssvali - 06-19-2013

i think instead of variables you can use Arrays.


RE: Read text from text file and save it into a variable in qtp - basanth27 - 06-19-2013

Split is the keyword you should be looking at. Then storing in variables would be easy.


RE: Read text from text file and save it into a variable in qtp - arpan - 06-19-2013

@ssvali : Thanks for your help.
@basanth27 : Thanks for your help.

I used Array and Split function and stored it in different variables. Again thanks ssvali and basanth27 for quick replies.