Page 1 of 1
Subtracting a field value from another field value
Posted: Tue Apr 25, 2023 11:13 am
by CAsba
Hi,
I've tried
Code: Select all
put fld "xxxx" into txxxx
put fld "fstock" into tfstock
subtract txxxx from tfstock
#put (fld "fstock" - fld "xxxx") into fld "fstock"
put tfstock into tstock
put tstock into theDataA["stock"]
Such a simple thing (!!) it would seem, but it's cost me many frustrating minutes, without success.
Please help.
Re: Subtracting a field value from another field value
Posted: Tue Apr 25, 2023 11:57 am
by Klaus
Did you "extract" theDataA from your datagrid first?
Don't see this in the code snippet.
And then you need of course write the array theDataA back into your datagid.
Re: Subtracting a field value from another field value
Posted: Tue Apr 25, 2023 12:12 pm
by CAsba
I think I did all that, here's the complete snippet:
Code: Select all
put fld "xxxx" & TAB into tCode
put the dgtext of grp "datagrid 3" into tText
put lineoffset(tCode,tText) into tline
if tLine = 0 then
beep
answer "No such code!"
exit to top
end if
put line tLine of tText into tFoundLine
#put tfoundline into fld "xxxx"
set itemdel to TAB
set the dghilite of grp "datagrid 3" to tfoundline
put the dgHilitedLines of group "Datagrid 3" into theLine
put the dgDataOfLine[theLine] of group "Datagrid 3" into theDataA
put theDataA["stock"]into fld "fstock"
put fld "xxxx" into txxxx
put fld "fstock" into tfstock
subtract txxxx from tfstock
#put (fld "fstock" - fld "xxxx") into fld "fstock"
put tfstock into tstock
put tstock into theDataA["stock"]
Re: Subtracting a field value from another field value
Posted: Tue Apr 25, 2023 12:35 pm
by Klaus
Yor forgot this at the end:
Code: Select all
...
put tfstock into tstock
put tstock into theDataA["stock"]
## This one:
set the dgDataOfLine[theLine] of group "Datagrid 3" to theDataA
...
Re: Subtracting a field value from another field value
Posted: Tue Apr 25, 2023 12:38 pm
by Klaus
Hint:
Code: Select all
...
set the dghilite of grp "datagrid 3" to tfoundline
...
the dgHilite is BOOLEAN value, so either TRUE or False!
Take a look in the dictionary for further infos.
Re: Subtracting a field value from another field value
Posted: Tue Apr 25, 2023 1:05 pm
by CAsba
Hi Klaus,
Thanks for that.
There's still a problem though at the line
error type subtract: error in source expression.
I'm baffled.
Re: Subtracting a field value from another field value
Posted: Tue Apr 25, 2023 1:15 pm
by Klaus
Hm, syntax is correct!?
Make sure there are definitively NUMBERS in those fields.
Re: Subtracting a field value from another field value
Posted: Tue Apr 25, 2023 1:17 pm
by dunbarx
CAsba.
Not sure what your actual data is, but that error comes when the values in those variables are not numeric. You cannot, say, subtract "42" from "A106"
Craig