best way to add a new line

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
cwkalish
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 78
Joined: Thu Sep 30, 2010 2:24 am

best way to add a new line

Post by cwkalish » Thu Jan 22, 2015 5:19 pm

Is there an easy way to write a new line in a field/container? I'd like to add a new line after the existing contents.
I can do, put return&"xyz" after fld "abc" but if I build up a field from scratch this way, I get a blank first line.
Thanks.
-Chuck

Klaus
Posts: 11834
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: best way to add a new line

Post by Klaus » Thu Jan 22, 2015 5:25 pm

Hi Chuck,

what about:

Code: Select all

...
put "xyz" into tNewLine
if fld "abc" <> EMPTY then
  put CR before tNewLine
end if
put tNewLine after fld "abc"
...
Been using this for years! :D


Best

Klaus

cwkalish
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 78
Joined: Thu Sep 30, 2010 2:24 am

Re: best way to add a new line

Post by cwkalish » Thu Jan 22, 2015 6:34 pm

Thanks. I thought there might be some neat way to do it without the conditional... Nice to know at least that part of my code isn't inelegant.

Klaus
Posts: 11834
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: best way to add a new line

Post by Klaus » Thu Jan 22, 2015 10:54 pm

I'm really sorry, that the only solution is not more erm... glamorous! :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6722
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: best way to add a new line

Post by dunbarx » Fri Jan 23, 2015 2:56 pm

I don't know about glamorous, but if you are really averse to conditionals, you could always:

Code: Select all

put "xyz" into line the number of lines of fld "yourField" + 1 of fld "yourField"
This does not care how many lines, or any at all, are in the field.

Craig Newman

Klaus
Posts: 11834
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: best way to add a new line

Post by Klaus » Fri Jan 23, 2015 3:04 pm

Hi Craig,

believe me, that is much more glamorous than my solution! :D


Best

Klaus

mattmaier
Posts: 109
Joined: Fri Apr 19, 2013 2:49 am

Re: best way to add a new line

Post by mattmaier » Sat Jan 24, 2015 10:12 pm

Yeah, that's clever. So the number of lines returns 0 if the field is empty. Neat.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6722
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: best way to add a new line

Post by dunbarx » Sun Jan 25, 2015 2:44 am

Glamorous, and now clever. Well, this is old, old magic.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”