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

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: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: best way to add a new line

Post by Klaus »

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 »

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: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: best way to add a new line

Post by Klaus »

I'm really sorry, that the only solution is not more erm... glamorous! :D
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: best way to add a new line

Post by dunbarx »

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: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: best way to add a new line

Post by Klaus »

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 »

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: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: best way to add a new line

Post by dunbarx »

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

Craig
Post Reply