How to programmatically select list item from value of a custom property

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
xyz
Posts: 30
Joined: Sat Feb 29, 2020 4:45 am

How to programmatically select list item from value of a custom property

Post by xyz » Sun Mar 29, 2020 12:44 am

I have saved a value in a custom property of a card (cpOwner). In a list on the card (lstOwner), I want to select the item in the list that matches the data in the custom property. How do I do that?

All of these efforts have failed with an error:

Code: Select all

   
   on preOpenCard
   	get the cpOwner of this card
   	--set the hilited of field "lstOwner" to it
   	--select it in field "lstOwner"
  	--select the cpOwner of field "lstOwner"
  end preOpenCard
BTW, I commented out the failed efforts in my code. That's why they are commented out here.

Thanks in advance.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: How to programmatically select list item from value of a custom property

Post by mwieder » Sun Mar 29, 2020 2:09 am

Code: Select all

set the hilitedLine of field "lstOwner" to it

xyz
Posts: 30
Joined: Sat Feb 29, 2020 4:45 am

Re: How to programmatically select list item from value of a custom property

Post by xyz » Sun Mar 29, 2020 2:54 am

Thanks for the reply.

Unfortunately hilitedLine returns (or sets) an item in a list using the line number. My custom property is a string. :( I want to match the string in the list with the string in my custom property. I was not at all clear on that in my first post. Sorry.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: How to programmatically select list item from value of a custom property

Post by mwieder » Sun Mar 29, 2020 3:15 am

Probably the lineOffset function is going to give you the best results.
That will give you a line number which you can then plug into the hilitedLine command.

xyz
Posts: 30
Joined: Sat Feb 29, 2020 4:45 am

Re: How to programmatically select list item from value of a custom property

Post by xyz » Sun Mar 29, 2020 3:29 am

That did it.

Code: Select all

   get the cpOwner of me
   put it into theOwner
   set the hilitedLine of field "lstOwner" to lineOffset(theOwner,field "lstOwner")
Many thanks!! :D

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: How to programmatically select list item from value of a custom property

Post by mwieder » Sun Mar 29, 2020 3:50 am

Yay! :D
If you want to get really fancy you could even shorten that to a single line

Code: Select all

set the hilitedLine of field "lstOwner" to lineOffset(the cpOwner of me,field "lstOwner")

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to programmatically select list item from value of a custom property

Post by Klaus » Sun Mar 29, 2020 10:03 am

Hi xyz,

welcome to the forum!

Here some great learning resources for the basics of LC, maybe start with "Controls" :-)
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

xyz
Posts: 30
Joined: Sat Feb 29, 2020 4:45 am

Re: How to programmatically select list item from value of a custom property

Post by xyz » Sun Mar 29, 2020 5:28 pm

Cool "compression" to a single line!! :P

Thanks for the welcome, Klaus. I'll check out the link.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to programmatically select list item from value of a custom property

Post by Klaus » Sun Mar 29, 2020 5:36 pm

Here another "compression":

Code: Select all

...
## get the cpOwner of me
## put it into theOwner
put the cpOwner of me into theOwner
...
No need to use GET and IT here first! :D

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”