Page 1 of 1

Hilitedlines and numbers

Posted: Sun Aug 30, 2015 9:23 am
by GregWills
Hi Everyone

I’m sure there is a simple solution to this problem, however I can’t see it right now!

I have a scrolling list field “conditions" with a list of conditions that I want to match with certain treatments listed in another field “corrections". These are to be combined and put into a field “Answers”.

The scrolling list field “corrections" is the one to select from and more than one line can be selected. This field has the list behaviour set to; multi-line, non-contiguous and click to toggle.

This script works perfectly for what I want … until I click beyond the 10th condition.

When I select line 11 of the list, the line 1 item also gets pasted into the (Answers) field. I understand that it would be related to the term ‘contains’, as 11 does ‘contain’ a 1.

Any suggestions on the correct script would be greatly appreciated. Thank you.


This is the script in field “Conditions";

on mouseup

put the hilitedlines of me into MySelection

put empty into field "Answers"

if MySelection contains "1," then

put line 7 of field "Corrections" of card id 1071 & ": (Discomfort)" && return after field "Answers"

end if

if MySelection contains "2" then

put line 6 of field "Corrections" of card id 1071 & ": (Pain)" && return after field "Answers"

end if

...

if MySelection contains "11," then

put line 8 of field "Corrections" of card id 1071 & ": (Lack of power in shoulder)" && return after field "Answers"

end if

end mouseup

Re: Hilitedlines and numbers

Posted: Sun Aug 30, 2015 10:26 am
by jmburnod
Hi Greg,

Welcome to this forum
I understand that it would be related to the term ‘contains’, as 11 does ‘contain’ a 1
Yes, you can avoïd this with something like that:

Code: Select all

put "," & the hilitedlines of me & "," into MySelection 
if MySelection contains ",1," then
best regards
Jean-Marc

Re: Hilitedlines and numbers

Posted: Sun Aug 30, 2015 10:57 am
by Dixie
In the script of the scrolling list field...

Code: Select all

on mouseDown
   put word 2 of the clickline into theLineNo
   put line theLineNo of me
end mouseDown

Re: Hilitedlines and numbers

Posted: Sun Aug 30, 2015 2:27 pm
by dunbarx
Hi.

I see you have answers.

Always consider rethinking your methods when some sort of kluge appears to be the only way out of a mess. In the field script, something like (pseudo):

Code: Select all

on mouseup
   get the hilitedLines of me 
   repeat for each item tItem in it
      doSomething tItem
      doSomethingElse tItem
   end repeat
end mouseup
Craig Newman

Re: Hilitedlines and numbers

Posted: Sun Aug 30, 2015 3:40 pm
by Klaus
HI Greg,

please tell us what is in a line in field "Conditions" and in field "Corrections".
Since they are related/referenced somehow, maybe we can combine both fields into one field!?

Most of the time a clever organisation of your data can make a lot of work obsolete.
Maybe you could start, if possible, to re-arrange your fields so line 1 of field "Conditions" relates to line 1
of field "Corrections", know what I mean?


Best

Klaus

Re: Hilitedlines and numbers

Posted: Mon Aug 31, 2015 1:48 am
by GregWills
Thank you all for your replies.

Jean-Marc, thank you for your “,1,” suggestion. I had done something similar, but not the comma before AND after. Excellent. This sorted out the problem.

Dixie, I didn’t try your suggestion, but am going to also try this.

Craig, thank you for your suggestion. I think your coding is far more elegant than mine will be. I baulk at the repeat function, therefore don’t try it. However once I get this draft version running I will try this approach, as it will be cleaner than what I have go so far!

Klaus. Thank you for your comment. I agree that this is most likely not an efficient way to link data with data. I need to reconsider ways to do this as my knowledge of Livecode increases. This is OK for my first draft, but I need to work on another way to get the item selected to match with other items under various conditions.

Cheers

Greg