Color
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Color
patrick,
would the textcolor do?
regards
Bernd
would the textcolor do?
Code: Select all
set the textcolor of word 5 to 9 of field "myField" to red
Bernd
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Color
Happens to all of us. We think it should be something really cryptic, and then we find out it's almost English.p4tr1ck wrote:I can't believe I didn't find that on the dictionary...
Almost. Then later we start looking for things expecting them to be really simple, and find some of them to be somewhat cryptic.

Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Color
I'm having some trouble using the textcolor property. How would I, say, set the selected text of a field to the color red?
It seems that every time I use your code exactly it works fine, but when I try it breaks
I've tried selectedChunk as well. What am I doing wrong?
Thanks for your help.
It seems that every time I use your code exactly it works fine, but when I try it breaks

Code: Select all
set the textcolor of the selectedText to red
Thanks for your help.

Re: Color
patrick,
the selectedText gives you the actual text.
You are looking for a chunk expression like "char 30 to 50 of field MyField"
The selectedChunk is what you are looking for. (tested)
If you are unshure what a particular keyword does I often code
put the selectedChunk of field 1
which puts the value of the expression into the message box.
regards
Bernd
the selectedText gives you the actual text.
You are looking for a chunk expression like "char 30 to 50 of field MyField"
The selectedChunk is what you are looking for.
Code: Select all
on mouseUp
put the selectedChunk of field 1 into tChunk
set the textColor of tChunk to red
end mouseUp
If you are unshure what a particular keyword does I often code
put the selectedChunk of field 1
which puts the value of the expression into the message box.
regards
Bernd
Re: Color
Sorry for the double post, but I'm getting some errors.
That brings up this error:
"button "Button": execution error at line 4 (Chunk: error in object expression), char 22"
I am using the correct field name...
Thanks,
Patrick
Code: Select all
on mouseUp
local tChunk
put the selectedChunk of field "userCode" into tChunk
set the textColor of tChunk to red
end mouseUp
"button "Button": execution error at line 4 (Chunk: error in object expression), char 22"
I am using the correct field name...
Thanks,
Patrick
Re: Color
Hi Patrick,
Something to remember when working with “selectedText” and “selectedChunk” is that clicking the mouse clears the selection, i.e. if I have a button containing the script:
... as in your example, it runs into the problem that, if I select some text, then click the button, I will by clicking the button clear the selection. If instead you have the script:
... select some text, then move the mouse over the button, the selectedChunk will be made red. Three things are worth noticing about the above script:
1. By using “mouseEnter”, the text we selected is still selected when the script runs, changing the textColor as desired.
2. “if the selection is not empty”... we need to put this condition in simply because, as this button uses “mouseEnter” if we happen to move the mouse into it without having selected some text, we would get an error. You could try “commenting out” the condition to see the problem, thus:
... and move the mouse into the button, without having selected any text. The problem would be the line:
... because, with no text selected, the selectedChunk is empty, thus tChunk is empty, and so Rev is now trying to set the textColor of an unspecified chunk of text to red, which generates an error. This was the problem with your script as well- clicking the button cleared the selection so nothing was selected when the script actually ran.
3. If, for example, there is only one field on the card (hence it is “field 1”) and it contains the single sentence “This is an example”- if you then select the first word:
the selectedText ... is “This”
the selectedChunk ... is “char 1 to 4 of field 1”
so, because the selectedChunk already specifies the field involved (field 1) it is not really necessary, as I understand it, to specify the field explicitly as in:
I should also mention that a simplified script would also work:
I hope this is of some help.
Regards,
Michael
Something to remember when working with “selectedText” and “selectedChunk” is that clicking the mouse clears the selection, i.e. if I have a button containing the script:
Code: Select all
on mouseUp
local tChunk
put the selectedChunk of field "userCode" into tChunk
set the textColor of tChunk to red
end mouseUp
Code: Select all
on mouseEnter
local tChunk
if the selection is not empty then
put the selectedChunk into tChunk
set the textColor of tChunk to red
end if
end mouseEnter
1. By using “mouseEnter”, the text we selected is still selected when the script runs, changing the textColor as desired.
2. “if the selection is not empty”... we need to put this condition in simply because, as this button uses “mouseEnter” if we happen to move the mouse into it without having selected some text, we would get an error. You could try “commenting out” the condition to see the problem, thus:
Code: Select all
on mouseEnter
local tChunk
-- if the selection is not empty then
put the selectedChunk into tChunk
set the textColor of tChunk to red
--end if
end mouseEnter
Code: Select all
set the textColor of tChunk to red
3. If, for example, there is only one field on the card (hence it is “field 1”) and it contains the single sentence “This is an example”- if you then select the first word:
the selectedText ... is “This”
the selectedChunk ... is “char 1 to 4 of field 1”
so, because the selectedChunk already specifies the field involved (field 1) it is not really necessary, as I understand it, to specify the field explicitly as in:
Code: Select all
the selectedChunk of fld "usercode"
Code: Select all
on mouseEnter
if the selection is not empty then
set the textColor of the selectedChunk to red
end if
end mouseEnter
Regards,
Michael
Re: Color
Hi Patrick,
Glad to hear things are working out. Something I should clarify:
... is perfectly valid, just more specific than:
... on its own. If you have several fields on a card, if you select text in any of them, the selectedChunk will be of the form “char(a) to (b) of field (whichever numbered field text was selected in)”, whereas:
... will be empty, unless the current selection is specifically in the field “usercode”. In some cases, you may want a script to operate on the selectedChunk regardless of which field the user is working on, so just “the selectedChunk” is very useful. On the other hand, there may well be design situations where as the developer you want things only applicable to a specific field. To be honest, I hadn’t realised you could specify the selectedChunk in this way, but I can well see how it could be very useful. Once again, I learn from my esteemed German colleague.
Regards,
Michael
Glad to hear things are working out. Something I should clarify:
Code: Select all
the selectedChunk of field “usercode”
Code: Select all
the selectedChunk
Code: Select all
the selectedChunk of field “usercode”
Regards,
Michael