Store formatted text in to variables

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
dayakar
Posts: 4
Joined: Wed May 15, 2013 12:28 pm

Store formatted text in to variables

Post by dayakar » Sat Apr 15, 2017 3:58 pm

Hi

Is it possible to put the formatted text of a field into a variable and then put the variable content into another field with the same formatting?

Please take a look at the following screenshot 1. In field 1, the backgroundcolor of word 2 is yellow and planning to put this word 2 along with the formatting into a variable and put the variable into field 2 with same formatting like in the field 1 as shown in screenshot 2.

Thanking you in advance.

Screenshot 1
Screen Shot 2017-04-15 at 8.17.19 PM.png
Screenshot 2
Screen Shot 2017-04-15 at 8.25.56 PM.png
Regards
Dayakar
--
Thanks,
Dayakar N

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Store formatted text in to variables

Post by richmond62 » Sat Apr 15, 2017 4:36 pm

Err . . . I cheated :)
Screen Shot 2017-04-15 at 6.34.53 pm.png
4matted text.livecode.zip
Here's the stack.
(1.07 KiB) Downloaded 184 times
You can make things even shorter by changing the script to this:
Screen Shot 2017-04-15 at 6.41.34 pm.png

dayakar
Posts: 4
Joined: Wed May 15, 2013 12:28 pm

Re: Store formatted text in to variables

Post by dayakar » Sat Apr 15, 2017 5:08 pm

Thank you very much Richmond for your alternative solution. The stack is helpful to know about clickText and the logic applied.

But good to know if there is an option to store the formatting info in the variable.
--
Thanks,
Dayakar N

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Store formatted text in to variables

Post by richmond62 » Sat Apr 15, 2017 5:34 pm

an option to store the formatting info in the variable
A variable can only store one value; and that would have to be either
your string (the word) or the RGB code for the backGroundColor, it could not be both.

dayakar
Posts: 4
Joined: Wed May 15, 2013 12:28 pm

Re: Store formatted text in to variables

Post by dayakar » Sat Apr 15, 2017 5:56 pm

Thanks for the response.

Is there any option in LiveCode to find the position of the word pasted using a variable in field? So, that position could be passed into another variable and set the color of the pasted text by referring to word Position as shown in the following code (it is not working but just to give an idea).

Code: Select all

put the position of CT in fld "f2" into CTPosition
set the backGroundColor of word CTPosition of fld "f2" to KOLOR
--
Thanks,
Dayakar N

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Store formatted text in to variables

Post by Klaus » Sat Apr 15, 2017 5:56 pm

HI dayakar,

to preserve formatting use "the htmltext of..." or "the rtftext of...".

Like this in your example:
...
set the htmltext of fld 1 to the htmltext of word 2 of fld 1
...


Best

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Store formatted text in to variables

Post by richmond62 » Sat Apr 15, 2017 9:07 pm

It would be interesting @Klaus to know why LiveCode seems unable to set Italic text on Mac OS (no problem on Linux: dunno anent Windows).

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Store formatted text in to variables

Post by Klaus » Sun Apr 16, 2017 9:08 am

No idea, works here in LC 9 dp6!
I used the LC "Text" menu for formatting.
Bildschirmfoto 2017-04-16 um 10.07.59.jpg

dayakar
Posts: 4
Joined: Wed May 15, 2013 12:28 pm

Re: Store formatted text in to variables

Post by dayakar » Sun Apr 16, 2017 2:38 pm

Thanks @Klaus it's working fine with htmlText.
--
Thanks,
Dayakar N

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

Re: Store formatted text in to variables

Post by dunbarx » Sun Apr 16, 2017 3:06 pm

Richmond.

I am still in v.6.7. I never noticed it before, but italic does not display correctly. The property sticks, just not the actual text. If it works in v9 as per Klaus, it might be interesting to see in which version it actually appeared, and if it was ever noted as such.

Craig

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Store formatted text in to variables

Post by Klaus » Sun Apr 16, 2017 3:34 pm

Just tested with LC 8.1.4 RC1, same result as in the screenshot above, in other words it works as exspected!

Post Reply