reference card in script by field value

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
CAsba
Posts: 452
Joined: Fri Sep 30, 2022 12:11 pm

reference card in script by field value

Post by CAsba »

Hi,
I have a template card that script copies to become a new customer account card. The name of the new card is the customer code. I want to run a button on the new card from another card. I have tried

Code: Select all

send mouseup to btn "new" of cd fld "newcode" of this card
but it doesn't work.
I guess I could do it another way, but I think it would involve more mouse clicks and I want to keep it as user-friendly as possible.
Any ideas how to amend my code to facilitate the send mouseup message to a button on a newly created card whose name is not known (yet) by the system, except as the contents of the field 'newcode'.
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: reference card in script by field value

Post by Klaus »

Hi CAsba,

always use quotes around the message(s) to send:

Code: Select all

send "mouseup" to ...
Put the content of the field into a variable first:

Code: Select all

...
put fld "newcode" into tTargetCard
send "mouseup" to btn "new" of cd tTargetCard
## No needd for "...of this cd" since LC always presumes that you mean the current card if nothing else is specified.
...
Best

Klaus
CAsba
Posts: 452
Joined: Fri Sep 30, 2022 12:11 pm

Re: reference card in script by field value

Post by CAsba »

Hi Klaus, Thanks for that.
Actually, I found another way,

Code: Select all

go to cd "CustomerAccountTemplate"
   clone this card
   set the name of cd "CustomerAccountTemplate" OF STACK "casba accounts - demo" to fld "newcode" of cd "enter new customer"
   send "mouseup" to btn "button1" 
and buuton1 - on the newly created card - does the business!
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: reference card in script by field value

Post by Klaus »

OK, I had no idea what you wanted to achieve, good you got it working.

Useful hint:
You can directly assign a new name to the cloned object with:

Code: Select all

clone this cd AS "new card name here"
CAsba
Posts: 452
Joined: Fri Sep 30, 2022 12:11 pm

Re: reference card in script by field value

Post by CAsba »

Hi Klaus,
That's VERY useful. Many thanks !
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: reference card in script by field value

Post by jacque »

When an object is created its id is placed in the "it" variable. So you could also do this :

Code: Select all

clone card x
set the name of it to <whatever>
Edit: Klaus' way is shorter.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: reference card in script by field value

Post by Klaus »

Je suis plus "lazy" que toi! :-D
CAsba
Posts: 452
Joined: Fri Sep 30, 2022 12:11 pm

Re: reference card in script by field value

Post by CAsba »

Many thanks, Jacque
Post Reply