Assigning a value to a card field

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
resty
Posts: 6
Joined: Tue Dec 13, 2016 11:01 pm

Assigning a value to a card field

Post by resty » Thu Dec 22, 2016 6:32 am

Hello,
How does one assign a value to a card field? I have a field defined as " rWord ". Then:

put the dgDataOfLine[theLine] of group "entriesGrid" into tWord
set the text of field "rWord" to tWord

But the second line does not assign the value of tWord (yes, it has a value) to the firled " rWord ". I tried many combinations with "set" and "put" but to no avail.

Help before I go nuts!

r

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

Re: Assigning a value to a card field

Post by Klaus » Thu Dec 22, 2016 11:40 am

Hi resty,

the functions "the dgDataOfLine[xxx]" and "the dgDataOfIndex[theLine]" return an ARRAY!
So you cannot put it into a field, you need to define a key of that array to put into your field.

Example:
...
put the dgDataOfLine[theLine] of group "entriesGrid" into tArray
put tArray["whatever"] into fld "rWord"
...
Consult the dictionary if in doubt! 8)
Starting with version 8 it also contains the DataGrid docs.


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Assigning a value to a card field

Post by dunbarx » Thu Dec 22, 2016 3:21 pm

Step through your handler, and you will see the array decomposed in the debugger. That is always a convenient place to see array contents.

Read about the "combine" command in the dictionary, just for practice and new knowledge.

Craig Newman

resty
Posts: 6
Joined: Tue Dec 13, 2016 11:01 pm

Re: Assigning a value to a card field

Post by resty » Thu Dec 22, 2016 6:18 pm

Klaus,
Thank you for your reply. So how do I, ah, uhm, create an index? I tried the following but no
cigar.

put the dgHilitedLines of group "entriesGrid" into theLine
put the dgDataofIndex[theLine] of group "entriesGrid" into tIndex
put the dgDataOfLine[theLine] of group "entriesGrid" into tWord
put tWord[tIndex[1]] into fld "rWord"

In the above, the content of tWord[tIndex[1]], is not being moved to "rWord".

Thanks for the help and cheers!

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

Re: Assigning a value to a card field

Post by Klaus » Thu Dec 22, 2016 6:43 pm

Hi resty,

that was just an example that these two DIFFERENT functions
-> dgDataofIndex[theLine]
and
-> dgDataOfLine[theLine]
are returning an ARRAY and not that you have to use both of them!

Did you name the columns in your datagrid?
If yes, then use these names for the keys, if not the columns will have the "deffault" names like
Col 1
Col 2
etc...
Get the picture?

Do like this:

Code: Select all

...
put the dgHilitedLines of group "entriesGrid" into theLine
## Since you used this line to get the currently highlited line, you need to stick to LINE now!
## Hint: LINE can be <> INDEX!
put the dgDataOfLine[theLine] of group "entriesGrid" into tSingleDimensionalArray
put tSingleDimensionalArray["name of your column here..."] into fld "rWord"
...

Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Assigning a value to a card field

Post by dunbarx » Thu Dec 22, 2016 7:00 pm

Do this in a button script:

Code: Select all

on mouseUp
   put "1st letter" into myArray["A"]
   put "2nd letter" into myArray["B"]
   put "3rd letter" into myArray["C"]
   breakpoint
   answer the keys of myArray
end mouseUp
First look at the variable "myArray" (the keys are in the variable name area, the values are in the value area). As I said, the debugger is a very nice tool to see array contents. The answer command will pull out those keys.

Craig

resty
Posts: 6
Joined: Tue Dec 13, 2016 11:01 pm

Re: Assigning a value to a card field

Post by resty » Thu Dec 22, 2016 11:20 pm

Klaus,
That works really well! Thanks for the Christmas gift! :wink:
Thanks to dunbarx for the enlightenment.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”