How to place a Label txt onto a text file.

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

How to place a Label txt onto a text file.

Post by Subas » Sun Jun 16, 2013 9:59 am

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

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

Post by Mark » Sun Jun 16, 2013 10:12 am

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

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

Post by Subas » Sun Jun 16, 2013 10:22 am

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

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

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

Post by Subas » Sun Jun 16, 2013 10:39 am

Dear Mark.

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

Best Regards

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

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

Post by Mark » Sun Jun 16, 2013 10:44 am

I'm glad that it work, Helen.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply