Datagrids & arrays
Bob Sneidar
bobs at twft.com
Thu Jun 2 12:21:45 EDT 2011
I agree that dgText is a good way to start, but sometimes parsing the data in a single variable can be more coding than working with arrays.
If you have either of the two excellent debuggers (GLX2 and Remo come to mind) try getting the dgData, set a breakpoint, and then examine the structure of the array. You will see that the row key is a numerical one, and the column keys are the column names.
Hence, if you had a datagrid called "dgNumbers" with three columns, numberOne, numberTwo and numberThree, you would do:
put the dgData of group "dgNumbers" into aNumbers
now you could say:
put aNumbers[1]["numberOne"] + aNumbers[1]["numberTwo"] into aNumbers[1]["numberThree"]
set the dgData of group "dgNumbers" to aNumbers
Voila! No text parsing to muck up the code and cloud the issue.
Even cleaner than this, you can get a single row from a datagrid:
put the dgDataOfIndex[1] of group "dgNumbers" into aRecord
put aRecord["numberOne"] + aRecord["numberTwo"] into aRecord["numberThree"]
set the dgDataOfIndex[1] of group "dgNumbers" to aRecord
Much simpler than scads of text parsing and you can be sure of the results. Be sure to check that the values are actually numbers before adding them unless you are absolutely sure about the state of the data.
if aRecord["numberOne"] & aRecord["numberTwo"] is a number then... else...
Bob
On Jun 2, 2011, at 5:47 AM, dunbarx at aol.com wrote:
> Use the dgText property. You can operate on this data in a script, and then reset.
>
>
> Craig Newman
>
>
>
>
>
> -----Original Message-----
> From: Van Brollini <analog_test at runbox.com>
> To: use-livecode at lists.runrev.com
> Sent: Thu, Jun 2, 2011 5:26 am
> Subject: Datagrids & arrays
>
>
> I have a datagrid with 1250 rows and 28 columns.
> The first 13 columns are data to be operated on. The last 15 columns are where
> the calculations are to be placed.
>
> I have gone through the datagrid manual and it is still fuzzy on how to get data
> OUT of the datagrid to do the calculations and then place the answers back INTO
> the datagrid.
>
> Any examples on how to this available?
>
> Thanks
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list