Quality Testing

Quality is delighting customers

' Read Content from a text file and Write in another text file
Dim objFso, myFile1, myFile2, x
Set objFso=createobject("Scripting.Filesystemobject")
Set myFile1=objFso.createtextfile("C:\Users\Renu\Desktop\RTQTP1.txt",1)
'Set myFile1=objFso.opentextfile("C:\Users\Renu\Desktop\RTQTP1.txt",1)

Set myFile1= objFso.OpenTextFile("C:\Users\Renu\Desktop\RTQTP1.txt", ForWriting,True)
myFile1.Write "This is a place to get all your qtp"

Set myFile2=objFso.createtextfile("C:\Users\Renu\Desktop\RTQTP2.txt",1)

Do Until myFile1.AtEndOfStream=True
x=myFile1.Readline
myFile2.Writeline x
Loop

myFile1.Close
myFile2.Close

Set objFso=Nothing

Set myFile1= objFso.OpenTextFile("C:\Users\Renu\Desktop\RTQTP1.txt", ForWriting,True) at this code i m getting error msg "Invalid procedure call or argument"

not able to write in text file so anybody look in to it.

Thaks

Views: 544

Reply to This

Replies to This Discussion

Hi Renu,

try below code

set x=createobject("scripting.filesystemobject")

sey y=x.opentextfile("c:\data.txt", 1)

set z=x.opentextfile("c:\data1.txt",2)

while not y.atendofstream

a=y.readline()

z.writeline()

print a

wend

regards,

Vijay

If this is all your code, then you are missing the constant declaration for "ForWriting".  The OpenTextFile parameter is actually a number and to open a file for writing it would be "2" however most people follow the standard of using Constants so the statement is more "readable" instead of trying to memorize what 1,2 and 8 mean.  But without it the system doesn't know what "ForWriting" is.  Add this below your "Dim" statement and it should work.

Const ForReading = 1, ForWriting = 2, ForAppending = 8   'FSO constants

 

Shawn
http://www.asi-test.com

Change the follwoing line

Set myFile2=objFso.createtextfile("C:\Users\Renu\Desktop\RTQTP2.txt",1)

to

Set myFile2=objFso.createtextfile("C:\Users\Renu\Desktop\RTQTP2.txt",2) 'for writing to file

Thanks,

Jay

Hi Renu,

Before the code u should declare like this , then it will work

    Const forReading = 1'to read the text file
    Const Forwriting=2'to write line in text file
    Const ForAppending = 8'to add the new line to existing text file,

Regard's

Raghavendra

Thanks to all . now my code is working

"

Dim objFso, myFile1, myFile2, x
Const ForReading = 1'to read the text file
Const Forwriting=2'to write line in text file
Set objFso=createobject("Scripting.Filesystemobject")
Set myFile1=objFso.createtextfile("C:\Users\Renu\Desktop\RTQTP1.txt",2)
myFile1.Write "This is a place to get all your qtp"
Set myFile2=objFso.createtextfile("C:\Users\Renu\Desktop\RTQTP2.txt",2)
Set myFile1=objFso.opentextfile("C:\Users\Renu\Desktop\RTQTP1.txt",1)
Do Until myFile1.AtEndOfStream=True
x=myFile1.Readline
myFile2.Writeline x
Loop

myFile1.Close
myFile2.Close

Set objFso=Nothing
"

thanks

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2020   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service