Referencing a text field from a different card

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
mgamson
Posts: 3
Joined: Tue Jun 11, 2013 3:08 am

Referencing a text field from a different card

Post by mgamson » Tue Jun 11, 2013 3:19 am

Complete noob teaching myself so please bear with me if this is covered somewhere, I really have searched.

I have learned how to populate a field with "chunks" from a different text field. Unfortunately I can only do this when the text field is part of the card I am working on. I have a number of different cards I would like them all to refer back to the same text field on the original card but somehow I can't find the syntax to make this happen.

Example

on mouseUp

set the itemDelimiter to ":"

get item 1 of field "linetest"

put item 1 of field "linetest" into line 1 of field "target"

end mouseUp

This works perfect as long as the field "linetest" is located within the card.
How can I make a button on a different card refer back to "linetest" on the original card?


Thanks in advance for any help you can give.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Referencing a text field from a different card

Post by Simon » Tue Jun 11, 2013 6:01 am

Hi mgamson,
Welcome to the forum! :)

You should lookup "name" in the dictionary
Try: "put the long name of this cd" in the Message Box (while you have your stack open).
Every control in LC has a name or ID, if you haven't directly named your Cards then your first card will be "card id 1002" then "card id 1003"etc.. (note: I hope you saw that even the name of the stack came back from the "put" above).

Since every control has a name or id you can address them directly:
"put field 1 of this cd into field 1 of cd id 1003"
Nice huh? :)
"set the label of button "myButton" of cd id 1003 to "LC is Fun!""

If I haven't been clear just write back.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

mgamson
Posts: 3
Joined: Tue Jun 11, 2013 3:08 am

Re: Referencing a text field from a different card

Post by mgamson » Tue Jun 11, 2013 7:14 am

WOW! brilliant!

Thank you so much. I knew I was missing something obvious. Incidentally after your suggestion, I realized the id number is displayed at the top of each property inspector window.

Thanks again for the quick response

MG

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

Re: Referencing a text field from a different card

Post by Klaus » Tue Jun 11, 2013 12:36 pm

HI MG,

I would highly recommend to give all your objects, cards and stacks meaningfull (= easy to remember!) names
so you do not need to use the IDs ;-)

And remember that you can address EVERYTHING with the correct "descriptoir", like:
...
put the text of fld "data entry" of cd "data entry card" of stack "data entry" into tVariable
...
Or even access objects from a substack in a stack that is not open:
...
put the text of fld "data entry" of cd "data entry card" of stack "data entry" of stack "path/to/stack/on_disk.livecode"into tVariable
...


Best

Klaus

mgamson
Posts: 3
Joined: Tue Jun 11, 2013 3:08 am

Re: Referencing a text field from a different card

Post by mgamson » Tue Jun 11, 2013 9:14 pm

Thanks for the tip Klaus.

I actually had given the object a unique identifier called "linetest" but I could not figure out the syntax to call it up from a different card and it would not call up directly by that name. The IDnumber solved the problem but I could see how this could get confusing to keep track of without descriptive names.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Referencing a text field from a different card

Post by Simon » Wed Jun 12, 2013 5:01 am

Hi MG,
My quick guess at the trouble is that you have to put the name in quotes, unlike ID.

put field 1 of this cd into field "linetest" of cd id 1003

Like the button example above.

Simon

EDIT:
A bit more:
put field "inputLine" of this cd into field "linetest" of cd "theOtherCard"
even more:
put field "inputLine" of cd "inputText" of stack "My First Stack" into field "linetest" of cd "theOtherCard" of stack "mySubStack"
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

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

Re: Referencing a text field from a different card

Post by CAsba » Thu Oct 20, 2022 11:10 am

SOLVED !
Just found I'd written 'in card "xxx"', should have been 'OF card "xxx"'
Duh !

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10096
Joined: Fri Feb 19, 2010 10:17 am

Re: Referencing a text field from a different card

Post by richmond62 » Thu Oct 20, 2022 11:15 am

If you keep an open mind learning LiveCode can be
a really exciting adventure.

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

Re: Referencing a text field from a different card

Post by Klaus » Thu Oct 20, 2022 11:16 am

No need to revive an almost 10 year old thread for this info... 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10096
Joined: Fri Feb 19, 2010 10:17 am

Re: Referencing a text field from a different card

Post by richmond62 » Thu Oct 20, 2022 12:06 pm

Some people take more than 10 years to find any fun at all. :wink:

Post Reply