Page 1 of 1
Handling change in textstyle of field lines
Posted: Thu Nov 05, 2020 11:15 am
by glenn9
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
Re: Handling change in textstyle of field lines
Posted: Thu Nov 05, 2020 11:26 am
by jmburnod
Hi Glen,
You may use:
Code: Select all
set the textstyle of line 3 of fld "myFld" to "underline"
Best regards
Jean-Marc
Re: Handling change in textstyle of field lines
Posted: Thu Nov 05, 2020 11:33 am
by glenn9
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
Re: Handling change in textstyle of field lines
Posted: Thu Nov 05, 2020 11:44 am
by Klaus
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
Re: Handling change in textstyle of field lines
Posted: Thu Nov 05, 2020 12:57 pm
by glenn9
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