Micro Focus QTP (UFT) Forums
Handling file 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: UFT / QTP Others (https://www.learnqtp.com/forums/Forum-UFT-QTP-Others)
+--- Thread: Handling file in QTP (/Thread-Handling-file-in-QTP)



Handling file in QTP - Ajit.2k6 - 03-05-2010

Hi All,

I know how to create a text file and how to write in them. Is there any way to update them? i mean not to overwrite the file but to add another lines?
Please help.

Thanks,

Ajit


RE: Handling file in QTP - Saket - 03-05-2010

Yes, Open your file in append mode instead of write mode.


RE: Handling file in QTP - Ajit.2k6 - 03-05-2010

Hi Saket,
I am trying as you have said but getting the invalid call procedure or argument.
My code is:
Code:
Dim fso, tf
   Set fso = CreateObject("Scripting.FileSystemObject")

    If (fso.FileExists ("c:\testfile.txt")) = True Then
Set tf = fso.OpenTextFile("c:\testfile.txt", ForAppending, True)

Else
   Set tf = fso.CreateTextFile("c:\testfile.txt", True)
  
   End If
   ' Write a line with a newline character.
'  tf.WriteLine("CashOnHand    TotalPortfolioWorth    ShareHoldingValue")
   ' Write a line.
   tf.Write (CashOnHand&"    "&TotalPortfolioWorth&"    "&ShareHoldingValue)
   tf.Close

Please correct me where i am wrong.

Thanks;

Ajit


RE: Handling file in QTP - Saket - 03-05-2010

you have not defined 'ForAppending' anywhere in the code
add 'ForAppending = 8' this line at top. or

use below statement -
Set tf = fso.OpenTextFile("c:\testfile.txt", 8, True)


RE: Handling file in QTP - Ajit.2k6 - 03-08-2010

Great Saket. It worked. but what was the reason of not running of the old line?

Thanks,

Ajit


RE: Handling file in QTP - Saket - 03-08-2010

refer the link for more details on this
http://msdn.microsoft.com/en-us/library/314cz14s(VS.85).aspx