Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Receiving syntax error when trying to append existing txt file

Status
Not open for further replies.

kdjonesmtb2

Technical User
Nov 19, 2012
93
US
Invalid procedure call or argument

Line (3616): "Set qfile = fso_OpenTextFile("m:\834 Test\Test files\qtptest2.x12", ForAppending,True)"

Set fso=createobject("Scripting.FileSystemObject")
Set qfile = fso_OpenTextFile("m:\834 Test\Test files\qtptest2.x12", ForAppending,True)
qfile.WriteLine("last line of text.")

qfile.Close
 
What value is set for 'ForAppending'?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I had commented that out - my mistake - I had not used this type of process before

'Const ForReading = 1, ForWriting = 2, ForAppending = 8
'Set FSO = CreateObject("Scripting.FilesystemObject")

Set fso=createobject("Scripting.FileSystemObject")
Set qfile = fso_OpenTextFile("m:\834 Test\Test files\qtptest2.x12", ForAppending,True)
qfile.WriteLine("last line of text.")

qfile.Close
 
ForAppending has to have a value, if you do not explicitly set the constant it will be 'Nothing'.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Hello,

I uncommented "Const ForReading = 1, ForWriting = 2, ForAppending = 8"

The script now runs to the end but I get the following:



Permission denied

Line (3617): "Set qfile = fso_OpenTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\Text files\qtptest2.x12", ForAppending,True)".

What could be causing this and how can I get access?

I was able to create the file using the following script


Set fso=createobject("Scripting.FileSystemObject")
'Create a non existing file "qtptest.txt " with overwrite option as True
'Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP Test 834\Text files\qtptest1.txt",true,False) ' textname could become a variable so that many could be generated
'Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP Test 834\Text files\ X",true,False)
'Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP Test 834\Text files\ &(DataTable.Value("TxtFileName",dtGlobalSheet)",true,False)
Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\Text files\" & TextFileName,true,False) 'TextFileName used as a variable so that multiple 834 files can be generated from DataTable
qfile1.Write((DataTable.Value("Interchange_Control_Header",dtGlobalSheet)))
qfile1.Write((DataTable.Value("Common_Delimiter",dtLocalSheet)))

qfile1.Write((DataTable.Value("ISA01_I01_Author_Info_Qualifier",dtGlobalSheet)))
 
Set the permissions on the folder to allow "Everyone" read/write access, the "My Documents" location is by default set to allow SYSTEM, Administrators and the local user access.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Note that this second question is cross-posted here: thread329-1717329
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top