Page 1 of 1
changing textcolor in a field takes FOREVER
Posted: Thu Nov 03, 2011 4:33 pm
by adventuresofgreg
Hi: I'm having a problem with setting textstyle and textcolor in a field with a script for iOS. I have a field with 90 lines, and the following script which looks at the content of each line and changes the color and textstyle of the line takes 20 SECONDS TO RUN on my iPad!!!!
Since you can only color and style text in a field (not in memory), I don't see any way around this??? Without the color or style changes, the field loads in about 3.5 seconds (due to other scripts involved).
I'm using LC v5.0
---------------
repeat for z
if item 4 of line x of thetextholder = "correct" then
set the textstyle of line x of field thetext to "bold"
set the textcolor of line x of field thetext to 0,140,0
end if
if item 4 of line x of thetextholder = "wrong" then
--set the textstyle of line x of field thetext to "bold"
set the textcolor of line x of field thetext to 220,0,0
end if
put x+1 into x
end repeat
Re: changing textcolor in a field takes FOREVER
Posted: Thu Nov 03, 2011 5:06 pm
by Klaus
Hi Greg,
did you "lock screen" and "unlock screen" before/after your changes?
...
lock screen
repeat for z
...
end repeat
unlock screen
...
Best
Klaus
Re: changing textcolor in a field takes FOREVER
Posted: Thu Nov 03, 2011 5:14 pm
by adventuresofgreg
oh ya. duh. I knew that.

Re: changing textcolor in a field takes FOREVER
Posted: Thu Nov 03, 2011 6:20 pm
by Klaus
Re: changing textcolor in a field takes FOREVER
Posted: Thu Nov 03, 2011 9:38 pm
by bn
to shorten FOREVER even a bit more:
Code: Select all
on mouseUp
put "0,140,0" into tGreen
put "220,0,0" into tRed
put "<p>" into tP
put "</p>" into tPEnd
put "<b>" into tB
put "</b>" into tBEnd
put "<font color=" & quote & tGreen & quote & ">" into tStartFontGreen
put "<font color=" & quote & tRed & quote & ">" into tStartFontRed
put "</font>" into tEndFont
put field "theText" into tData -- take the field into a varible, a lot faster
put field "theTextHolder" into theTextHolder -- assuming your variable theTextHolder comes from a field of the same name
put 1 into tCounter
repeat for each line aLine in theTextHolder
if item 4 of aLIne = "correct" then
put tP & tStartFontGreen & tB & line tCounter of tData & tBEnd & tEndFont & tPEnd & return after tCollect -- bold and green
end if
if item 4 of aLine = "wrong" then
--put tP & tStartFontRed & tB & line tCounter of tData & tBEnd & tEndFont & tPEnd & return after tCollect -- bold and red
put tP & tStartFontRed & line tCounter of tData & tEndFont & tPEnd & return after tCollect -- just red
end if
add 1 to tCounter
end repeat
delete last char of tCollect
set the htmlText of field "NewHTML" to tCollect -- for testing you make a new field,
-- set the htmlText of field "theText" to tCollect -- in your app you probably would want to put it back into field "theText"
end mouseUp
I had a similar problem on a slow iPhone G3 and resorted to do the coloring and setting bold by constructing the html on the fly.
It is orders of magnitude faster then setting the attributes of a line of a field etc.
kind regards
Bernd
PS I can hear you even without all caps. No need yelling.
Re: changing textcolor in a field takes FOREVER
Posted: Thu Nov 03, 2011 10:19 pm
by bn
Hi,
here is the stack I used to test this in the IDE.
Kind regards
Bernd
Re: changing textcolor in a field takes FOREVER
Posted: Fri Nov 04, 2011 12:06 am
by adventuresofgreg
Yes, thank you. That is MUCH more efficient.
