Page 1 of 1

Appending Data to a text file

Posted: Tue Oct 03, 2023 5:33 pm
by trags3
Hi,
I had this working on an older project but that was somehow tossed into the never to be seen again space.
I am trying to put several fields on a page into a csv text file.

Here is the code I am using:

on mouseUp
open file specialFolderPath("documents/Vipw/") & "tLine5.txt" for append
put fld"LN5" & "," & fld"expDate5" & "," & the Label of btn"M5" & "," & Fld"IC5" & "," & fld"5Q" & "," & fld"Date5" & "," & fld"Init5" & "," & fld"LN5QTYINV" & cr into tData
answer tData
write tData to file specialFolderPath("documents/Vipw/") & "tLine5.txt"
go cd"MainMenu"
end mouseUp

I am using the answer statement to make sure the data is actually getting into the tData variable correctly. It is and once
I get this working I will remove it.

The write statement is not working. Nothing gets added to the tLine5.txt file.

I am trying to save the data in a file that can be eventually printed out when needed.
Thanks ahead of time for the answer to my problem
Tom

Re: Appending Data to a text file

Posted: Tue Oct 03, 2023 6:01 pm
by Klaus
Hi Tom,

you need to use the specialfolderpath codes WITHOUT adding something to them!
Means: There is NO folder -> specialFolderPath("documents/Vipw/")
This should work:

Code: Select all

on mouseUp   
   ## Save typing:
   put specialFolderPath("documents") & "/Vipw/tLine5.txt" into tFile
   open file tFile for append
   put fld"LN5" & "," & fld"expDate5" & "," & the Label of btn"M5" & "," & Fld"IC5" & "," & fld"5Q" & "," & fld"Date5" & "," & fld"Init5" & "," & ld "LN5QTYINV" & cr into tData
   answer tData
   write tData to file tFile
   
   ## IMPORTANT!
   close file tFile
   go cd"MainMenu"
end mouseUp
I always use the shorter URL syntax:

Code: Select all

on mouseUp  
   put specialFolderPath("documents") & "/Vipw/tLine5.txt" into tFile
   put fld"LN5" & "," & fld"expDate5" & "," & the Label of btn"M5" & "," & Fld"IC5" & "," & fld"5Q" & "," & fld"Date5" & "," & fld"Init5" & "," & ld "LN5QTYINV" & cr into tData
   put tData AFTER url("file:" & tFile)
end mouseUp
And please use the CODE tags after pasting your script(s) here.

Best

Klaus

Re: Appending Data to a text file

Posted: Tue Oct 03, 2023 6:19 pm
by trags3
Thanks Klaus,
I will make sure I save this.
It works as I had hoped.

Tom

Re: Appending Data to a text file

Posted: Tue Oct 03, 2023 7:00 pm
by SparkOut
One observation: "tLine5.txt" is a string literal, so you will always be writing to the file literally called "tLine5.txt" - if that's what you want, all well and good. Are you sure you don't want a variable filename according to the value in the tLine5 variable? You might need to

Code: Select all

put specialFolderPath("documents") & "/Vipw/" & tLine5 & ".txt" into tFile
to get the variable filename.