Appending Data to a text file

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
trags3
Posts: 418
Joined: Wed Apr 09, 2014 1:58 am
Location: Las Vegas, NV

Appending Data to a text file

Post by trags3 » Tue Oct 03, 2023 5:33 pm

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

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Appending Data to a text file

Post by Klaus » Tue Oct 03, 2023 6:01 pm

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

trags3
Posts: 418
Joined: Wed Apr 09, 2014 1:58 am
Location: Las Vegas, NV

Re: Appending Data to a text file

Post by trags3 » Tue Oct 03, 2023 6:19 pm

Thanks Klaus,
I will make sure I save this.
It works as I had hoped.

Tom

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Appending Data to a text file

Post by SparkOut » Tue Oct 03, 2023 7:00 pm

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.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”