There seems to be a problem with totaling up a group of subform values! (Version 1.0.2)
Here is a sample of the code I am using.
var vCnt As Int
var vLoop As Int
var vNetGain as double
vCnt = @FormResultSetTotal("Transactions Form")
vLoop = 1
while vLoop <= vCnt
{
vNetGain = vNetGain + @ToMoney( @FormFieldValue("Transactions Form", "Amount", vLoop) )
// writeln("vLoop= " + vloop + " vNetGain= " + vnetgain)
vLoop += 1
}
@msg("Net Gain = $" + vNetGain)
This is set to activate at MainForm :: OnElementEntry. After testing, I'm pretty certain the problem is that the @FormFieldValue() function is only able to retrieve the value of the first subrecord in time to be used in the loop.
So what happens is the @FormFieldValue gets the first subform's value, then since it's NOT being updated with the rest of them, the loop just keeps calculating with that first value (essentially multiplying it by the number of subrecords).
The reason I think the function is not getting the values in time, is that if you click on another element to re-trigger the code, it produces the correct total. And by that time, all the subrecords have already been retrieved. So this indicates that the code is not flawed.
Lanticans, can you let me know what your experience is with this?