Hilitedlines and numbers

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
GregWills
Posts: 69
Joined: Sun Aug 30, 2015 7:51 am

Hilitedlines and numbers

Post by GregWills » Sun Aug 30, 2015 9:23 am

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

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

Re: Hilitedlines and numbers

Post by jmburnod » Sun Aug 30, 2015 10:26 am

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
https://alternatic.ch

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Hilitedlines and numbers

Post by Dixie » Sun Aug 30, 2015 10:57 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Hilitedlines and numbers

Post by dunbarx » Sun Aug 30, 2015 2:27 pm

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

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

Re: Hilitedlines and numbers

Post by Klaus » Sun Aug 30, 2015 3:40 pm

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

GregWills
Posts: 69
Joined: Sun Aug 30, 2015 7:51 am

Re: Hilitedlines and numbers

Post by GregWills » Mon Aug 31, 2015 1:48 am

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

Post Reply