Handling change in textstyle of field lines

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
glenn9
Posts: 234
Joined: Wed Jan 15, 2020 10:45 pm

Handling change in textstyle of field lines

Post by glenn9 » Thu Nov 05, 2020 11:15 am

Hi everyone,

I would like to conditionally change the textstyle of lines in a field based on whether a card exists in a substack

I've put together this code

Code: Select all

 
   repeat for each line x in  field 1
      If exists(card x of stack"SubStack") then
         set the textstyle ["underline"] of line x of field 1 to true
      else
         set the textstyle ["underline"] of line x of field 1 to false
      end if
   end repeat
   
but it throws the following error message: 'chunk: error in range start expression' for the line:

Code: Select all

set the textstyle ["underline"] of line x field 1 to true
Grateful for any hints or tips on where I'm going wrong with this code?

Many thanks,

Kind regards,

Glenn

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Handling change in textstyle of field lines

Post by jmburnod » Thu Nov 05, 2020 11:26 am

Hi Glen,
You may use:

Code: Select all

set the textstyle of line 3 of fld "myFld" to "underline"
Best regards
Jean-Marc
https://alternatic.ch

glenn9
Posts: 234
Joined: Wed Jan 15, 2020 10:45 pm

Re: Handling change in textstyle of field lines

Post by glenn9 » Thu Nov 05, 2020 11:33 am

jmburnod wrote:
Thu Nov 05, 2020 11:26 am
Hi Glen,
You may use:

Code: Select all

set the textstyle of line 3 of fld "myFld" to "underline"
Best regards
Jean-Marc
Hi Jean-Marc,

Thanks for responding so quickly. Just tried it out and it certainly underlines line 3 but doesn't take account of the condition, if the card exists in the substack.

If I change your code slightly replacing line 3 with line x

Code: Select all

set the textstyle of line x of fld "myFld" to "underline"
I get the same error as before?

Kind regards,

Glenn

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Handling change in textstyle of field lines

Post by Klaus » Thu Nov 05, 2020 11:44 am

Hi Glenn,

what is in field 1?

Hint:
"repeat for each line x" does NOT count the lines, so the linenumber is NOT in X, but instead the CONTENT of that line!
Maybe that is the problem? Sounds like...

If yes, you need to supply and manage your own counter:

Code: Select all

...
put 1 into tCounter
 repeat for each line x in  field 1
      If exists(card x of stack"SubStack") then
         set the textstyle ["underline"] of line tCounter of field 1 to true
      else
         set the textstyle ["underline"] of line tCounter of field 1 to false
      end if
      add 1 to tCounter
   end repeat
...
That is the reason why "repeat for EACH" is so much faster that "repeat with..."
LC does not need to count the lines, it just passes the content of EACH line.

Best

Klaus

glenn9
Posts: 234
Joined: Wed Jan 15, 2020 10:45 pm

Re: Handling change in textstyle of field lines

Post by glenn9 » Thu Nov 05, 2020 12:57 pm

Hi Klaus,

brilliant, it works perfectly now. Thank you.

Field 1 contains a list of strings.

I hadn't appreciated that the 'for each' command passed Content, although I should have noticed this, as I was asking x to pass both content (in terms of the card name) and also further on, a line number at the same time!

Apologies for the muddled thinking.

Thank you again for your help.

Kind regards,

Glenn

Post Reply