Naming File with Entered Variables
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Naming File with Entered Variables
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
Hi ldblalock,
Welcome to this forum
Best regards
Jean-Marc
Welcome to this forum
yes. something like that :Is there a way to do this?
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
Jean-Marc
https://alternatic.ch
Re: Naming File with Entered Variables
That works brilliantly, thank you!
Lisa
Lisa
Re: Naming File with Entered Variables
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
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