Micro Focus QTP (UFT) Forums
Error while opening text file through 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: Error while opening text file through QTP (/Thread-Error-while-opening-text-file-through-QTP)



Error while opening text file through QTP - SarodeGirish - 06-14-2012

Hello All,

Code:
set fsoObj=createobject("scripting.filesystemobject")
set file=fsoObj.opentextfile("D:\bhim\one.txt", Forwriting, true)

After executing the above code I am getting the error as "Invalid procedure call or argument" . the path "D:\bhim\one.txt" does exist.

Thanks & regards

Girish sarode


RE: Error while opening text file through QTP - manabh - 06-14-2012

After set fsoObj=createobject("scripting.filesystemobject") verify fsoObj <> nothing


RE: Error while opening text file through QTP - Shridevi.Salagare - 06-14-2012

Name of the file should not be file..as its a keyword.Use some other name.

Try this code

Code:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
   Dim fsoObj, FileName
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set FileName = fso.OpenTextFile("D:\bhim\one.txt", ForWriting, True)
   FileName.Write "Hello world!"
   FileName.Close



RE: Error while opening text file through QTP - ssvali - 06-14-2012

Hi,
There are two mistakes in ur code
1. file - is a default keyword, it should not be used.
2. Instead of ForWriting you have to use number, ie - 2
Const 1 = ForReading, 2 = ForWriting, 8 = ForAppending

Try below code

Code:
Set fsoObj=createobject("scripting.filesystemobject")
Set Ofile = fsoObj.OpenTextFile("D:\bhim\one.txt",2,TRUE)
(06-14-2012, 04:13 PM)manabh Wrote: After set fsoObj=createobject("scripting.filesystemobject") verify fsoObj <> nothing



RE: Error while opening text file through QTP - SarodeGirish - 06-16-2012

It's executed.

Thanks Shridevi
Hello All,

Dim oBrowser
Set oBrowser = Description.Create


While ececuting the above code in .vbs file only,I am getting the error as "object required Description". I am not using QTP.

Many thanks for viewing this thread.
-Girish


RE: Error while opening text file through QTP - sandya - 06-25-2012

Please try this code:
Code:
create for reading=1,create for writing=2,create for append mode=8.
Dim Fso, Myfile.
Set Fso=createobject("scripting.Filesystemobject")
Set Myfile=Fso.opentextFile("E:\project\file.txt",for writing,True)
Myfile.write"write value" & "result"
Myfile.close