SetDataOfLine and Repeat--I'm missing something

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
AZSun
Posts: 30
Joined: Tue Mar 20, 2012 10:44 pm

SetDataOfLine and Repeat--I'm missing something

Post by AZSun » Mon Dec 04, 2017 12:13 am

Hi,
I'm working with datagrids in the form style. It is just a little demo stack to see how to add across rows. I have text fields "SmallNumber", "BigNumber", and "TotalNumber". I have the datagrid script populate SmallNumber and BigNumber from my array of data. Then, it adds them together and places the answer in the text field TotalNumber. I wanted to save the contents of the field TotalNumber back to the array under the column/key called "CombinedEventTotal" that is already created--but whose element is empty at the moment.

I believe SetDataOfLine will do what I want. I can successfully do it one by one not using a repeat. :D
Thus, my trouble might be the repeat or the getting of the text out of the text field in the repeat process.

Here is how I used SetDataOfLine where it works without a loop. I have the code in the behavior script. Then, I have to click on each text field "TotalNumber" after that each answer is saved to the array.

Code: Select all

##Works to transfer field text to an array column/key element
on mouseUp pMouseBtnNum
   if pMouseBtnNum is 1 then
      ## did they click on the text field?
      if the short name of the target is "TotalNumber" then
         ## Update internal value in data grid
         SetDataOfLine the dgLine of me, "CombinedEventTotal", the text of the target 
      end if
   end if
end mouseUp
When viewing printkeys data all is good and updated in the array.

Now here's where I have problems.

Code: Select all

on mouseUp
   repeat with theLineNo = 1 to the dgNumberOfLines of group "DataGrid 1"
      ## Get text value for each row
      put the text of field "TotalNumber" into tTheLineSolution
      dispatch "setDataOfLine" to group "DataGrid 1" with theLineNo,"CombinedEventTotal",tTheLineSolution
   end repeat
 end mouseUp
This takes the value for Record 1 for text field "TotalNumber" and puts it in all records for key "CombinedEventTotal" So, for my numbers 11 is written to all records in the array. The text fields still show the correct math as expected.
My Data looks like this in the text fields.
1 10 11
2 20 22
0 30 33
and like this in the array data
1 10 11
2 20 11
0 30 11

Thank you for pointers to what I'm forgetting,

AZSun
Posts: 30
Joined: Tue Mar 20, 2012 10:44 pm

Re: SetDataOfLine and Repeat--I'm missing something

Post by AZSun » Sun Dec 10, 2017 3:08 am

Ok, I got it working. I needed to put the SetDataOfLine in the fillin part of the script for the behavior of the DataGrid. Then it automatically grabs the data from the text field and enters/saves it back into the Array.

Code: Select all

on FillInData pDataArray
   -- This message is sent when the Data Grid needs to populate
   -- this template with the data from a record. pDataArray is an
   -- an array containing the records data.
   -- You do not need to resize any of your template's controls in
   -- this message. All resizing should be handled in resizeControl.
   set the text of field "fSmallNumber" of me to pDataArray["smallNumber"]
   set the text of field "fBigNumber" of me to pDataArray["bigNumber"]
   put field "fSmallNumber" of me+field "fBigNumber"of me into field"fCombinedNumber"of me
   setDataOfLine the dgLine of me, "CombinedTotal", the text of field "fCombinedNumber" of me
   
   -- Example:
   set the text of field "Label" of me to pDataArray["label 1"]
end FillInData
This experiment of mine is really a combination of the Aggregate Values Tutorial (adding columns even when viewing the DataGrid as a form) and the Checkbox Tutorial (It shows how to save things back to the array). I'm posting an image of my stack that shows adding across and adding down in a DataGrid.
Attachments
AddAcross&Down.png
AddAcross&Down.png (26.92 KiB) Viewed 1782 times

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”