Setting Text Style Based on Word in Field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Setting Text Style Based on Word in Field
Hi Folks,
Having trouble with this as I'm just getting started in LC.
With a field named month listing the following:
Month 1
2nd
4th
etc.
Month 2
12th
17th
etc.
I am wanting to set the textStyle to link for all lines that contain the word "Month".
Have been modifying the below script without success.
on mouseUp
put field "month" into tmonth
repeat with x = 1 to the number of lines in tmonth
if line 1 contains "Month" then
set the textStyle of it to link
put tTest22 into field "test22"
end if
end repeat
end mouseUp
Any help much appreciated!
Having trouble with this as I'm just getting started in LC.
With a field named month listing the following:
Month 1
2nd
4th
etc.
Month 2
12th
17th
etc.
I am wanting to set the textStyle to link for all lines that contain the word "Month".
Have been modifying the below script without success.
on mouseUp
put field "month" into tmonth
repeat with x = 1 to the number of lines in tmonth
if line 1 contains "Month" then
set the textStyle of it to link
put tTest22 into field "test22"
end if
end repeat
end mouseUp
Any help much appreciated!
Re: Setting Text Style Based on Word in Field
Hi J316,
1. welcome to the forum!
2. This should do the trick, please note my comments!
3. Please take a look at these stacks to get more of the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
1. welcome to the forum!

2. This should do the trick, please note my comments!
Code: Select all
on mouseUp
put field "month" into tMonth
## To speed up things when working with fields, we lock the screen!
## Since fields are quite complex to draw, we might see LC working line by line otherwise :-D
lock screen
repeat with x = 1 to the number of lines of tmonth
## if line 1 contains "Month" then
## You want to check ALL lines and not only line 1, right?
## Looks like all the lines START with Month, so I used ...BEGINS WITH... here, if not chage back to ...CONTAINS...
if line i of tMonth begins with "Month" then
## set the textStyle of it to link
## IT is not used anywhere in this handler so it may contain
## ANYTHING (from an earlier command/functoin) or NOTHING!
## We change the according line in the actual field:
set the textstyle of line i of fld "Month" to "link"
## tTest222 is also not defined in this handler so you will see the string tTest 22 in fld "test22"
## put tTest22 into field "test22"
end if
end repeat
## Done!
unlock screen
end mouseUp
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Re: Setting Text Style Based on Word in Field
Try this.
Code: Select all
on mouseUp
put field "month" into tmonth
repeat with x = 1 to the number of lines in tmonth
if line x of tmonth contains "Month" then
set the textStyle of line x of tmonth to link
put tTest22 into field "test22"
end if
end repeat
end mouseUp
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
Re: Setting Text Style Based on Word in Field
Hi Tom,
...
set the textStyle of line x of tmonth to link
...
"tMonth" is a variable!
Best
Klaus
...
set the textStyle of line x of tmonth to link
...
"tMonth" is a variable!

Best
Klaus
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Re: Setting Text Style Based on Word in Field
OOps.
Code: Select all
set the textStyle of line x of fld "month" to link
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
Re: Setting Text Style Based on Word in Field
Hey again Klaus,
I guess I'm a little confused about the lines in fields from your comment about All of them starting with Month. My assumption was for the
below example that only lines 1 and 5 begin with Month...as they would appear in the contents of a field?? I am trying to have "Month 1" and "Month 2" only to become links.
Month 1
2nd
4th
etc.
Month 2
12th
17th
etc.
I did try the script with "starts with" and "contains", no quotes, of course. It returned an error both ways:
execution error at line 12 (Chunk: error in range start expression),char 1
This is the line in the script: if line i of tMonth contains "Month" then
Thanks much for the help. I know this is elementary for you folks, but I will get better...promise!
I guess I'm a little confused about the lines in fields from your comment about All of them starting with Month. My assumption was for the
below example that only lines 1 and 5 begin with Month...as they would appear in the contents of a field?? I am trying to have "Month 1" and "Month 2" only to become links.
Month 1
2nd
4th
etc.
Month 2
12th
17th
etc.
I did try the script with "starts with" and "contains", no quotes, of course. It returned an error both ways:
execution error at line 12 (Chunk: error in range start expression),char 1
This is the line in the script: if line i of tMonth contains "Month" then
Thanks much for the help. I know this is elementary for you folks, but I will get better...promise!
Re: Setting Text Style Based on Word in Field
Hi J316,
sorry, I made a little typo in my script, lets see if you can spot it, too:
Best
Klaus
sorry, I made a little typo in my script, lets see if you can spot it, too:
Code: Select all
...
repeat with x = 1 to the number of lines of tmonth
if line i of tMonth begins with "Month" then
...
set the textstyle of line i of fld "Month" to "link"
...
Klaus
Re: Setting Text Style Based on Word in Field
Ah! Klaus,
Thanks for the little challenge...I do appreciate it. Sorry about the delay...my day job got in the way! I changed the i's to x's since the initial repeat was defined that way. I am also assuming, and will try i for this also, it is like a variable and can be most anything one would like it to be as long as one is consistent in the script.?
I also removed the quotes from:
set the textstyle of line x of fld "Month" to "link"
making it:
set the textstyle of line x of fld "Month" to link --I suppose this is optional?
All worked fine and I really appreciate it.
Klaus...this wasn't actually my first post. I saw some folks viewed my first one, but did not respond. I assumed I just ask a stupid question or maybe it wasn't posted in the correct place in the forum. Would you mind looking below at my first post and tell me if it's a stupid question, in the wrong place or, if you will, address it. I really wanted to make a decision on the below item before I got too far along in my efforts. Thanks again, very much! And here it is:
"Hi Folks,
This is my first posting a question here and thanks for all you are doing to help.
I am reading about retrieving text files that are located on a server, but am not sure what the most efficient way to proceed might be. My app is almost exclusively dealing with text. I have created several fields for displaying the text stored in the field contents, but I'm concerned that with the volume of text I will ultimately have, it may slow down the app. I am not interested (at this point) in writing to the server. In reading, I saw a suggestion of using the "load" command as being asynchronous and also being able to dump the cache. But I also wondered if using FTP would be as good a choice. I'm just too new to this stuff (about a month in) to trust my own instincts.
I have a text file stored on my web server, but forum says I can't post web links. Need help with that for future I suppose?
Might you point me in the direction you think is best for me to proceed? Thanks upfront for any help and again for all you do!
J316"
Thanks for the little challenge...I do appreciate it. Sorry about the delay...my day job got in the way! I changed the i's to x's since the initial repeat was defined that way. I am also assuming, and will try i for this also, it is like a variable and can be most anything one would like it to be as long as one is consistent in the script.?
I also removed the quotes from:
set the textstyle of line x of fld "Month" to "link"
making it:
set the textstyle of line x of fld "Month" to link --I suppose this is optional?
All worked fine and I really appreciate it.
Klaus...this wasn't actually my first post. I saw some folks viewed my first one, but did not respond. I assumed I just ask a stupid question or maybe it wasn't posted in the correct place in the forum. Would you mind looking below at my first post and tell me if it's a stupid question, in the wrong place or, if you will, address it. I really wanted to make a decision on the below item before I got too far along in my efforts. Thanks again, very much! And here it is:
"Hi Folks,
This is my first posting a question here and thanks for all you are doing to help.
I am reading about retrieving text files that are located on a server, but am not sure what the most efficient way to proceed might be. My app is almost exclusively dealing with text. I have created several fields for displaying the text stored in the field contents, but I'm concerned that with the volume of text I will ultimately have, it may slow down the app. I am not interested (at this point) in writing to the server. In reading, I saw a suggestion of using the "load" command as being asynchronous and also being able to dump the cache. But I also wondered if using FTP would be as good a choice. I'm just too new to this stuff (about a month in) to trust my own instincts.
I have a text file stored on my web server, but forum says I can't post web links. Need help with that for future I suppose?
Might you point me in the direction you think is best for me to proceed? Thanks upfront for any help and again for all you do!
J316"
Re: Setting Text Style Based on Word in Field
Hi J316,
If in doubt, always take a look into the dictionary!
Your first posting can be found here:
http://forums.livecode.com/viewtopic.ph ... 43#p135343
And it looks that someone just answered your question!
Best
Klaus
it actually IS a variable, a temoprary one, but a real and valid variable!J316 wrote:Ah! Klaus,
Thanks for the little challenge...I do appreciate it. Sorry about the delay...my day job got in the way! I changed the i's to x's since the initial repeat was defined that way. I am also assuming, and will try i for this also, it is like a variable and can be most anything one would like it to be as long as one is consistent in the script.?

No, that is correct syntax with quotes!J316 wrote: I also removed the quotes from:
set the textstyle of line x of fld "Month" to "link"
making it:
set the textstyle of line x of fld "Month" to link --I suppose this is optional?
If in doubt, always take a look into the dictionary!

Your first posting can be found here:
http://forums.livecode.com/viewtopic.ph ... 43#p135343
And it looks that someone just answered your question!
Best
Klaus
Re: Setting Text Style Based on Word in Field
Thanks again, Klaus. Will do!