Inserting seperate lines into text field

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
Wynn
Posts: 4
Joined: Mon Jul 12, 2010 10:16 am

Inserting seperate lines into text field

Post by Wynn » Mon Feb 14, 2011 10:26 am

I am stuck on a rather simple problem that i cant get my head around, how do i make a button insert data into a text field, but make it start a new line for each new piece of data entered? Normally the program would replace the old data with the new instead of making them both share the same text box. Now, me being a complete newbie at this, i dont even know how to start going around this... Help would be appreciated!

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

Re: Inserting seperate lines into text field

Post by Mark » Mon Feb 14, 2011 11:48 am

Wynn,

Code: Select all

put cr & mySomeVar after fld "Some Field"
Make sure to read the user manual.

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Inserting seperate lines into text field

Post by dunbarx » Mon Feb 14, 2011 3:25 pm

Mark's idea is perfectly correct, you can write a return BEFORE the new data you wish to append, So that if you have:

AAA
BBB

in your field, if you put return & "CCC" into that field, the return will force the data to be written into the next line:

AAA
BBB
CCC

Just as if you typed the return and then the "CCC". I only mention this so that I can ask you to consider the other way to do it:

put the number of lines of fld "yourField" + 1 into entryLine
put yourData into line entryLine of fld "yourField"

You use a property of the field to ascertain the target line number. I frequently add data to adjacent linked fields, some of which may have a different number of lines. I need to know that any new data I add will always be below the field with the most number of lines, and this is a way to do it.

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: Inserting seperate lines into text field

Post by BvG » Mon Feb 14, 2011 5:54 pm

Uhm.. I can't see any advantage of first getting the number of lines, in fact for large datasets it'd be slowing down a bit? Is it so you don't need to use a return? Just curious about why you do it that way. If i need a super clean way of adding lines, I do this:

Code: Select all

if the number of lines in field "target" > 0 then
  put return & "new line" after field  "target"
else
  put "new line" into field "target"
end if
in your field, if you put return & "CCC" into that field, the return will force the data to be written into the next line:
you probably meant to say:
in your field, if you put return & "CCC" after that field, the return will force the data to be written into the next line:
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Inserting seperate lines into text field

Post by dunbarx » Mon Feb 14, 2011 6:17 pm

Right on about the "after".

I have several apps where adjacent fields contain various data, and there is a single "title" line of data that corresponds to perhaps several lines of data in the adjacent fields. If I add a new data set, I need to know the extent of the longest multi-line fields in order to properly set the line where the new "title" line will go. Then I will put each "record" into, not after, that "entryline". I agree that in a single field, return & data will always find the next line.

My point was that by using a function (not property, as I said. Too fast, too fast...) one can get considerable additional control. The number of lines in one field determines the entry line in another.

jsburnett
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 121
Joined: Fri Mar 09, 2007 9:47 pm

Re: Inserting seperate lines into text field

Post by jsburnett » Tue Feb 15, 2011 4:32 am

Another way is ...
put newData into line (the number of lines of field "Old Data" + 1) of field "Old data"

Thanks.

Post Reply