Page 1 of 1

How to place a Label txt onto a text file.

Posted: Sun Jun 16, 2013 9:59 am
by Subas
Hello everybody. I am new to Live code. I just started 2 day ago. I was poking around the help pages but unable to find this info and would request help from the live code gurus.

Basically I have a Label named "Name" and a text field call name. I managed to copy what the user enters into the text field name into the text file which is saved on the desktop but I am not able to copy the Label name which is "Name" onto the text file.

Can some please explain the codes to place the Label name "Name" onto the text file and write beside that is the text field called name.

As such the text file will look like this

Name: Helen

Currently with the below code i get this:

Helen

Code: Select all


global yourName
global myText

on mouseUp
   // save what the user types into our variables 
   
   put field "name" into yourName
   
   // now use them
   
   answer "You are " & yourName
   
   open file specialFolderPath("desktop") & "/vr.txt" for write 
   put yourName into myText
   write label of Name "Name" & return to vr.txt 
   write myText to file specialFolderPath("desktop") & "/vr.txt" 
   close file specialFolderPath("desktop") & "/vr.txt" 
   
end mouseUp

Thank you

Re: How to place a Label txt onto a text file.

Posted: Sun Jun 16, 2013 10:12 am
by Mark
Hi Helen,

Welcome to the forum. Do you see any errors when you execute your script? If you do, you should always post the complete text of the error together with your question in this forum.

It isn't entire clear to me what you want to do. Do you want to save the label field together with a name to a text file or do you want to give the text file the same name as the label? In the following, I assume that you have a field "Label" and a field "Name".

To write thelabel field together with thename field, you can do this:

Code: Select all

put specialFolderPath("desktop") & "/vr.txt" into myFile
open file myFile for write
write fld "Label" && fld "Name" to file myFile
close file myFile
If you want the file to have the same name as the label, you could do this:

Code: Select all

put specialFolderPath("desktop") & slash & field "Label" into myFile
open file myFile for write
write fld "Label" && fld "Name" to file myFile
close file myFile
You can also use the put command instead of the open-write-close structure:

Code: Select all

put specialFolderPath("desktop") & slash & field "Label" into myFile
put fld "Label" && fld "Name" into url ("binfile: & myFile)
Kind regards,

Mark

Re: How to place a Label txt onto a text file.

Posted: Sun Jun 16, 2013 10:22 am
by Subas
Dear Mark.

i am sorry when i compiled it there was an error on the part "write label of Name "Name" & return to vr.txt"

i knew the issue was at this line but i was not able to call the text of the label. what i wanted was to to write the label field together with the name field as shown by your example into a txt file on my desktop.

thank you very much for the help and quick assistance. very much appreciated. i will try it now. Thanks again.

best regards

Re: How to place a Label txt onto a text file.

Posted: Sun Jun 16, 2013 10:39 am
by Subas
Dear Mark.

Thank You for the explanation. I tested the code and it works perfectly. Thank You very much. :)

Best Regards

Re: How to place a Label txt onto a text file.

Posted: Sun Jun 16, 2013 10:44 am
by Mark
I'm glad that it work, Helen.

Mark