Page 1 of 1
Naming File with Entered Variables
Posted: Wed Jul 20, 2011 8:29 pm
by ldblalock
I'm using LiveCode to program a memory experiment in which each individual will be assigned a unique ID. Currently, my first card is one with a field to enter the ID and a 'start' button that will launch the instructions. I'd like to have the program also take the number entered into the field and use it to name a txt file where I will store the data from the task (for example, if I enter 23 in the field, I'd like the data file to be called "23.txt"). I've figured out how to write variables to the file okay, but not how to name the file based on the entered variable. I'm very new to LiveCode so I could be missing something very obvious. Is there a way to do this?
Re: Naming File with Entered Variables
Posted: Wed Jul 20, 2011 9:17 pm
by jmburnod
Hi ldblalock,
Welcome to this forum
Is there a way to do this?
yes. something like that :
Code: Select all
on savemyID
put fld "MYID" into tTheID --•• the fld "MYID" contains the ID user
put tTheID&".txt" into tNameFile
ask file "Save" with tNameFile --••Æor e path you builded
if it = empty then exit savemyID
open file it for write
write mydata to file it --•• mydata = the data to write
close file it
end savemyID
Best regards
Jean-Marc
Re: Naming File with Entered Variables
Posted: Wed Jul 20, 2011 9:36 pm
by ldblalock
That works brilliantly, thank you!
Lisa
Re: Naming File with Entered Variables
Posted: Thu Jul 21, 2011 12:32 pm
by Klaus
Hi Lisa,
in case you are as lazy as moi, I can recommend the shorter URL syntax
Reading/writing is a one-liner!
Write text to disk:
...
put fld "your field with text here" into url("file:" & "name of file.txt")
## or
## put your_variable_with_text into url...
...
Read text from disk:
...
put url("file:" & "name of file.txt") into fld "your field here"
...
If you are dealing with BINARY data, like images etc., use "binfile:" instead of "file:" .
Check URL in the dictionary for more info.
Best from germany
Klaus