Superscript of subscript
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Superscript of subscript
I'm new to Revolution and working with a 30 day license.
In my first app I have a field with a number of text items. For many of these text items I use the 'textShift' feature to sub- or superscript a specific character in a text item string. When a user selects one of these text items, I place the selected text into a label. However, the text in the label does not include the sub- or superscript, only the straight text.
Does anyone know how I can get selected text with sub- or superscript characters to automatically display correctly in a label?
Thanks in advance for your ideas...pwr
In my first app I have a field with a number of text items. For many of these text items I use the 'textShift' feature to sub- or superscript a specific character in a text item string. When a user selects one of these text items, I place the selected text into a label. However, the text in the label does not include the sub- or superscript, only the straight text.
Does anyone know how I can get selected text with sub- or superscript characters to automatically display correctly in a label?
Thanks in advance for your ideas...pwr
Re: Superscript of subscript
Did some quick tests and came up with this.
It does what you want by iterating through the first field, and setting the second field to match. Seems a bit clunky, but it works.
Edit: Removed array method. It was badly thought out.
There is probably another way, but i'm still pretty new, and don't know what it is if there is. If the amount of text to process isn't too large, the iteration method should work fine. The other method would be a royal pain I believe.
Code: Select all
on mouseUp
put "This is a test" into field "Field"
set the textShift of word 2 of field "Field" to -4
set the textShift of char 1 of field "Field" to 4
put field "Field" into field "field2"
repeat with i = 1 to the number of chars in field "Field"
if the textShift of char i of field "Field" is not empty then
get the textShift of char i of field "Field"
set the textShift of char i of field "field2" to it
end if
end repeat
end mouseUp
Edit: Removed array method. It was badly thought out.
There is probably another way, but i'm still pretty new, and don't know what it is if there is. If the amount of text to process isn't too large, the iteration method should work fine. The other method would be a royal pain I believe.
pwr wrote:I'm new to Revolution and working with a 30 day license.
In my first app I have a field with a number of text items. For many of these text items I use the 'textShift' feature to sub- or superscript a specific character in a text item string. When a user selects one of these text items, I place the selected text into a label. However, the text in the label does not include the sub- or superscript, only the straight text.
Does anyone know how I can get selected text with sub- or superscript characters to automatically display correctly in a label?
Thanks in advance for your ideas...pwr
Sorry, but I was away for a few days. Thanks for the suggestion using the array, I think it might work for me as my text strings are short (<25-30 chars).
As far as my script goes, here it is...
on selectionChanged
--update the input unit label with the selected input unit
put the selectedText of me into field "fldSelectedInputUnit"
--check to see that the needed data is available
--and re-calculate unit conversion
if the text of field "fldSelectedInputUnit" is not empty then
if the text of field "fldSelectedOutputUnit" is not empty then
if the text of field "fldInputValue" is a number then
ConvertUnits
end if
end if
end if
end selectionChanged
The key line is the first put.
Thanks again for your responses...pwr
As far as my script goes, here it is...
on selectionChanged
--update the input unit label with the selected input unit
put the selectedText of me into field "fldSelectedInputUnit"
--check to see that the needed data is available
--and re-calculate unit conversion
if the text of field "fldSelectedInputUnit" is not empty then
if the text of field "fldSelectedOutputUnit" is not empty then
if the text of field "fldInputValue" is a number then
ConvertUnits
end if
end if
end if
end selectionChanged
The key line is the first put.
Thanks again for your responses...pwr
Sorry, to ask for additional help, but I modified the code sample given to me above to use the selectedText. Although the compiler doesn't have a problem I get a run-time error on the indicated line.
Here's my script...
on selectionChanged
--update the input unit label with the selected input unit
put the selectedText of me into field "fldSelectedInputUnit"
--test code to put in sub- and superscript
repeat with i = 1 to the number of chars in selectedText of me
if the textShift of char i of selectedText of me is not empty then --ERROR OCCURS HERE
get the textShift of char i of selectedText of me
set the textShift of char i of field "fldSelectedInputUnit" to it
end if
end repeat
--end test code
--check to see that the needed data is available
--and re-calculate unit conversion
if the text of field "fldSelectedInputUnit" is not empty then
if the text of field "fldSelectedOutputUnit" is not empty then
if the text of field "fldInputValue" is a number then
ConvertUnits
end if
end if
end if
end selectionChanged
The error says:
execution error at line 7 (Chunk: can't find object), char 24
What's wrong with my syntax that the char chunk can't find my object????
Here's my script...
on selectionChanged
--update the input unit label with the selected input unit
put the selectedText of me into field "fldSelectedInputUnit"
--test code to put in sub- and superscript
repeat with i = 1 to the number of chars in selectedText of me
if the textShift of char i of selectedText of me is not empty then --ERROR OCCURS HERE
get the textShift of char i of selectedText of me
set the textShift of char i of field "fldSelectedInputUnit" to it
end if
end repeat
--end test code
--check to see that the needed data is available
--and re-calculate unit conversion
if the text of field "fldSelectedInputUnit" is not empty then
if the text of field "fldSelectedOutputUnit" is not empty then
if the text of field "fldInputValue" is a number then
ConvertUnits
end if
end if
end if
end selectionChanged
The error says:
execution error at line 7 (Chunk: can't find object), char 24
What's wrong with my syntax that the char chunk can't find my object????
Edit: Its not working exactly right for me, but i'm too foggy at the moment to figure out why. Should get you close if nothing else.
Heres whats going on I think.
I don't think you can address selectedText by char number within the selected text. So what you need to do in your selectionChanged handler is check that somethign is actually selected, (rather than an entry point which is still considered a selection)
Then, you need to get the start and end position of the text thats selected. YOu can use selectedChunk to do this, word 2 of selectedChunk is the start char, word 4 is the end char. At this point you have all the information needed to do the processing. Heres a quick example.
I'm out of things for a while, but if you need more help, send me another PM and i'll hop on and look.
Heres whats going on I think.
I don't think you can address selectedText by char number within the selected text. So what you need to do in your selectionChanged handler is check that somethign is actually selected, (rather than an entry point which is still considered a selection)
Then, you need to get the start and end position of the text thats selected. YOu can use selectedChunk to do this, word 2 of selectedChunk is the start char, word 4 is the end char. At this point you have all the information needed to do the processing. Heres a quick example.
Code: Select all
on selectionChanged
put word 2 of the selectedChunk into tStart
put word 4 of the selectedChunk into tEnd
if not(tStart - tEnd = 1) then -- checks to make sure its not just an insertion point
put the selectedText into field "Field2" -- if somethign is really selected, then move the text to the other field
repeat with i = tStart to tEnd -- repeat from the start char num to the end char num of the selection
if the textShift of char i of me is not empty then -- Check the field itself, NOT the selection text
get the textShift of char i of me -- Get the textShift setting
set the textShift char (i - tStart) of field "Field2" to it -- Transfer it to the new field, adjusting char position left to the 1 position.
end if
end repeat
end if
end selectionChanged
pwr wrote:Sorry, to ask for additional help, but I modified the code sample given to me above to use the selectedText. Although the compiler doesn't have a problem I get a run-time error on the indicated line.
Here's my script...
on selectionChanged
--update the input unit label with the selected input unit
put the selectedText of me into field "fldSelectedInputUnit"
--test code to put in sub- and superscript
repeat with i = 1 to the number of chars in selectedText of me
if the textShift of char i of selectedText of me is not empty then --ERROR OCCURS HERE
get the textShift of char i of selectedText of me
set the textShift of char i of field "fldSelectedInputUnit" to it
end if
end repeat
--end test code
--check to see that the needed data is available
--and re-calculate unit conversion
if the text of field "fldSelectedInputUnit" is not empty then
if the text of field "fldSelectedOutputUnit" is not empty then
if the text of field "fldInputValue" is a number then
ConvertUnits
end if
end if
end if
end selectionChanged
The error says:
execution error at line 7 (Chunk: can't find object), char 24
What's wrong with my syntax that the char chunk can't find my object????
Hi pwr,
You asked the same question somewhere else. I've answered your question there.
Best regards,
Mark
You asked the same question somewhere else. I've answered your question there.
Best regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Thank you both for the advice. It's good to get the same answer from two sources!
Sturgis, I used your code sample and it seemed to work fine for me after I changed the 'char (i-tstart)' to just 'char i'.
I need to read up and make sure I understand/appreciate the difference between a selectedText and selectedChunk.
Anyway, thank you both...pwr
Sturgis, I used your code sample and it seemed to work fine for me after I changed the 'char (i-tstart)' to just 'char i'.
I need to read up and make sure I understand/appreciate the difference between a selectedText and selectedChunk.

Anyway, thank you both...pwr