Keep formatting when moving text
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Keep formatting when moving text
How can I keep the formatting of text (i.e., super and subscripts) when using "Put" to move text from one text field to another?
Thanks, David
Thanks, David
Re: Keep formatting when moving text
Hi David,
you can't! PUT will only put "naked" ASCII text into a field.
But you can use the htmltext (and maybe the RTFTEXT prop, but never used that one) property to preserve formatting, something like:
...
set the htmltext of fld "the formerly empty field" to the htmltext of fld "the formatted one"
...
Best
Klaus
you can't! PUT will only put "naked" ASCII text into a field.

But you can use the htmltext (and maybe the RTFTEXT prop, but never used that one) property to preserve formatting, something like:
...
set the htmltext of fld "the formerly empty field" to the htmltext of fld "the formatted one"
...
Best
Klaus
Re: Keep formatting when moving text
Hi David,
welcome to the forum.
If you say "put the text of field "f1" into field "f2", or "put field "f1" into field "f2" which is the same, you just take the text without formatting, as you have found out.
There is the htmlText of field "f1" that contains the formatting information.
will do the trick.
you can get the htmlText of chunks too and say
the styledText of a field is also a property of the field that contains formatting information
so
would give you the same result as "htmlText"
Since htmlText, styledText, unicodeText, formattedText are properties of a field you have to use the
"set the [your property here] instead of put.
Oh, if your want to have a look at the htmlText of a field you can say
here you have the actual html in field 2, not the formatted text of field "f1"
Kind regards
Bernd
Edit: I just see that Klaus was faster.
welcome to the forum.
If you say "put the text of field "f1" into field "f2", or "put field "f1" into field "f2" which is the same, you just take the text without formatting, as you have found out.
There is the htmlText of field "f1" that contains the formatting information.
Code: Select all
set the htmlText of field "f2" to the htmlText of field "f1"
you can get the htmlText of chunks too and say
Code: Select all
set the htmlText of char 1 to 10 of field "f2" to the htmlText of word 10 to 35 of field "f1"
so
Code: Select all
set the styledText of field "f2" to the styledText of field "f1"
Since htmlText, styledText, unicodeText, formattedText are properties of a field you have to use the
"set the [your property here] instead of put.
Oh, if your want to have a look at the htmlText of a field you can say
Code: Select all
put the htmlText of field "f1" into field "f2"
Kind regards
Bernd
Edit: I just see that Klaus was faster.
Re: Keep formatting when moving text
&*^%$^#^*
Klaus is ALWAYS faster.
Grumble...
Klaus is ALWAYS faster.
Grumble...
Re: Keep formatting when moving text
Thank you for the response, but there is this issue: I am adding the formatted text with super/subscripts to a field which already has text in it. (What I am really doing is creating a test from selected question cards.) The set command replaces any text in the destination field with the text in the source field. What you wrote about "put the htmlText..." looks promising though, if I could flip the htmltext (after I put it after last line of the destination fld) back to showing sub or superscripts. It could all be done transparently, much like how a browser transparently converts htmlText to formatted text (bold, italics, super/sub, etc.). This is undoubtedly an amateur-hour solution to an easy question but I am grateful for any help.
Re: Keep formatting when moving text
Hi David,
if you want to append the formattedText of field "f1" (source) to field "f2" (destination) at the end of field "f2" in a new line you could do this
Kind regards
Bernd
if you want to append the formattedText of field "f1" (source) to field "f2" (destination) at the end of field "f2" in a new line you could do this
Code: Select all
on mouseUp
set the htmlText of field "f2" to the htmlText of field "f2" & return & the htmlText of field "f1"
end mouseUp
Bernd
Re: Keep formatting when moving text
Hi.
What Bernd said.
Know that when you are able to manipulate chunks of text, you are able to use such keywords as "after", "before" and "into":
put yourText after fld 2 --works
but
put yourHTMLText after fld 2. --This syntax does not hunt.
Because the HTMLText is a property, not a chunk, and therefore must be handled differently. You can only "set" and "get" properties. You cannot "put" them or, say, "delete" them. So what Bernd told you to do was to extract those properties and then re-assemble them (pseudoCode):
set the property of mainThing to (the property of mainThing) & return & (the property of secondaryThing)
The (new) property of mainThing is thus assembled from two other properties, concatenated with a return in this example.
Craig Newman
What Bernd said.
Know that when you are able to manipulate chunks of text, you are able to use such keywords as "after", "before" and "into":
put yourText after fld 2 --works
but
put yourHTMLText after fld 2. --This syntax does not hunt.
Because the HTMLText is a property, not a chunk, and therefore must be handled differently. You can only "set" and "get" properties. You cannot "put" them or, say, "delete" them. So what Bernd told you to do was to extract those properties and then re-assemble them (pseudoCode):
set the property of mainThing to (the property of mainThing) & return & (the property of secondaryThing)
The (new) property of mainThing is thus assembled from two other properties, concatenated with a return in this example.
Craig Newman
Re: Keep formatting when moving text
Thank you both so much! This really helps.