Micro Focus QTP (UFT) Forums
Reading and writing is the same text file - 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Reading and writing is the same text file (/Thread-Reading-and-writing-is-the-same-text-file)



Reading and writing is the same text file - poulomi21b - 07-08-2014

Hi

I want to read the data from a text file and write the result for that data set in the text file at the same time how can i do that in QTP

File Format:-
DATE##FLYFROM##FLYTO##NAME##TICKET##Result
073014##Denver##Paris##Test1##1
072514##Paris##Denver##Test2##2

I want to write the result (pass/fail) under the RESULT col.

Code:-
Code:
systemutil.run"C:\Program Files (x86)\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").WinEdit("Agent Name:").Set "mercury"
Dialog("Login").WinEdit("Password:").SetSecure "53ba23c99f935b004bba9a2ac1279aec43b6e7d8"
Dialog("Login").WinButton("OK").Click

Set FSO = createobject("scripting.fileSystemObject")
'FSO.CreateFolder("D:\Poulomi\Test1")
'FSO.CreateTextFile("D:\Poulomi\Sample1.txt")
'set Ofile1= FSO.OpenTextFile("D:\Poulomi\Sample2.txt",2)
Set Ofile = FSO.OpenTextFile("D:\Poulomi\Sample2.txt",1)
'Ofile.Write"HELLO"

Ofile.SkipLine
While Ofile.AtEndOfStream <> true
    resobj = Ofile.readline
'    msgbox resobj
    arrobj = split(resobj,"##")
    dtdate = arrobj(0)
    flyfrom = arrobj(1)
    flyto = arrobj(2)
    name = arrobj(3)
    txt = arrobj(4)
    
'    msgbox dtdate
'    msgbox flyfrom
'    msgbox flyto
'    msgbox name
'    msgbox txt
      
'Ofile1.Write"##"

Window("Flight Reservation").ActiveX("MaskEdBox").Type dtdate
Window("Flight Reservation").WinComboBox("Fly From:").Select flyfrom
Window("Flight Reservation").WinComboBox("Fly To:").Select flyto
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set name
Window("Flight Reservation").WinButton("Insert Order").Click
Window("Flight Reservation").Dialog("Flight Reservations").WinButton("OK").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;New Order"

Wend
Ofile.Close
Set Ofile=nothing
Set FSO=nothing

Can someone please help me with this


RE: Reading and writing is the same text file - pranikgarg - 07-08-2014

Code:
systemutil.run"C:\Program Files (x86)\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").WinEdit("Agent Name:").Set "mercury"
Dialog("Login").WinEdit("Password:").SetSecure "53ba23c99f935b004bba9a2ac1279aec43b6e7d8"
Dialog("Login").WinButton("OK").Click

Set FSO = createobject("scripting.fileSystemObject")
'FSO.CreateFolder("D:\Poulomi\Test1")
'FSO.CreateTextFile("D:\Poulomi\Sample1.txt")
'set Ofile1= FSO.OpenTextFile("D:\Poulomi\Sample2.txt",2)
Set Ofile = FSO.OpenTextFile("D:\Sample2.txt",1)
'Ofile.Write"HELLO"

Ofile.SkipLine
While Ofile.AtEndOfStream <> true
resobj = Ofile.readline
'    msgbox resobj
arrobj = split(resobj,"##")
dtdate = arrobj(0)
flyfrom = arrobj(1)
flyto = arrobj(2)
name = arrobj(3)
txt = arrobj(4)
'
'msgbox dtdate
'msgbox flyfrom
'msgbox flyto
'msgbox name
'msgbox txt

'Ofile1.Write"##"


'Window("Flight Reservation").ActiveX("MaskEdBox").Type dtdate
Window("Flight Reservation").WinObject("Date of Flight:").Type dtdate
Window("Flight Reservation").WinComboBox("Fly From:").Select flyfrom
Window("Flight Reservation").WinComboBox("Fly To:").Select flyto
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set name
Window("Flight Reservation").WinButton("Insert Order").Click

If(Window("Flight Reservation").WinObject("Insert Done").GetVisibleText = "Insert Done...") Then
    MsgBox "Pass"
Else
    MsgBox "Fail"
End if

Window("Flight Reservation").WinButton("Button").Click

Wend
Ofile.Close
Set Ofile=nothing
Set FSO=nothing


Check out this code.


RE: Reading and writing is the same text file - poulomi21b - 07-08-2014

Thanks for the reply but I want to write the result in the same file from where I am reading. I think your code is writing the output in the msgbox.