Saving data to a 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
bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Saving data to a file

Post by bjb007 » Thu Jun 26, 2008 12:47 am

I want to save data from an array to
a text file.

I have the file name made up of a text string and
the result of the "seconds" command plus ".txt"

However I can find a way to make this work in
the usual way such as

put url ("file:" & "numbers.txt") into myData
put myData & "27," into myData
put myData into url ("file:" & "numbers.txt")

Any help appreciated.
Life is just a bowl of cherries.

Nomi
Posts: 19
Joined: Wed Feb 27, 2008 4:08 pm

Post by Nomi » Thu Jun 26, 2008 12:54 am

You don't need the & statement in the put url.

I think it would read:

put url "File:numbers.txt" into mydata

and

put myData into url "File:numbers.txt"

- Noel

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Saving data to a file

Post by bjb007 » Thu Jun 26, 2008 7:07 am

Noel

Thanks for the tip.

The problem is, I think, that the file
name I want to use isn't "numbers.txt"
but something like "fred1234.txt" and
it's only available in a variable.

BTW the code I posted above works
for "numbers.txt".
Life is just a bowl of cherries.

Tim
Posts: 29
Joined: Wed Oct 31, 2007 12:56 pm

Post by Tim » Thu Jun 26, 2008 7:19 am

Try

put myData into URL ( "file:fred" & the seconds & ".txt")

Regards,

Tim

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Can any object do this...

Post by bjb007 » Thu Jun 26, 2008 3:15 pm

Thanks Tim.

Do you know the magic to make Rev
put this file into the same directory
as the app which makes it?

Just an't get my old brain to figure
this out!
Life is just a bowl of cherries.

Tim
Posts: 29
Joined: Wed Oct 31, 2007 12:56 pm

Post by Tim » Thu Jun 26, 2008 3:52 pm

Here is a little chunk of script that will output the data into a file in the same directory as the engine is running from :

local tFullEnginePath
local tEngineFolder
set the itemdel to ":"
put item -2 to -1 of the address into tFullEnginePath
set the itemdel to "/"
put item 1 to -2 of tFullEnginePath & "/" into tEngineFolder
put myData into URL("file:" & tEngineFolder & "fred" & the seconds & ".txt")

Hope this is what you were after.

Regards,

Tim.

Post Reply