Normal Topic "posting" to subform (Read 709 times)
CapitalG
Full Member
Members
***
Offline



Posts: 143
Location: Phoenix, Arizona
Joined: Mar 4th, 2003
"posting" to subform
Oct 29th, 2010 at 1:50am
Print Post Print Post  
Running Sesame 2.52.  Parent form is "Data".  Subform is "Detail".  I am trying to run calculations to figure what percent each record of a subform is to the total.  I then multiply that result by a field in the parent form.  I then want to put the result back in the subform in the record used in the calculation.  The code below is my attempt.  This code is in the "On Element Entry" of a command button.  

When I first ran it, I had all of the writeln's within the code active and all the information was correct.  However, nothing "posted".  After some playing I enclosed the results in @ToNumber and everything seemed to work fine.  On subsequent tests, some of the items post and some don't.  There is usually at least one row in the subform that does not have data filled in.  Even in these instances, the writeln shows all of the numbers calculating properly.  If I click in the row, sometimes the numbers will fill in and sometimes not.  

I am sure I have broken some rule, but can't figure it out.  Thanks for any direction you can give.

[code]#include "sbasic_include.sbas"

var vKey as int

var VRSKey as String
var vNoOfRecords as Double
var vTotal as String
var vloop as Double
var vTotpmt as Double
var vIndpercnt as Double
var vLE2 as Double      
var vLE3 as Double      
var vLE4 as Double
var vActSoft as Double
var vActHard as Double
var vSoft as Double
var vHard as Double
var vIndtot as double


vLE2 = LE2
vLE3 = LE3
vActSoft = Act.Soft
vActHard = Act.Hard
vKey = ParID
//writeln("vKey  " + vKey)
VRSKey = @XResultSetSearch(@FN, "Data!Detail", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "ChildID=" + vKey)
if(vRSKey > -1)
{
vNoOfRecords = @XResultSetTotal(vRSKey)
//writeln ("vNoOfRecords  " + vNoOfRecords)
vTotal = 0
for vLoop = 1 to vNoOfRecords
XResultSetCurrentPosition(vRSKey, vLoop)
vSoft = @XResultSetValue(vRSKey, "Soft")
vHard = @XResultSetValue(vRSKey, "Hard")
//writeln("vLE2  " + vLE2)
//writeln("vLE3  " + vLE3)
//writeln("vActSoft  " + vActSoft)
//writeln("vActHard  " + vActHard)
//writeln("vSoft  " + vSoft)
//writeln("vHard  " + vHard)
vIndpercnt = vSoft/vLE2
vLE4 = vHard/VLE3
vIndtot = vIndpercnt * vActSoft
vTotpmt = vLE4 * vActHard
//writeln("Soft  " +vIndtot)
//writeln("Hard  " +vTotpmt)
XResultSetValue(vRSKey, "ActSoft", @ToNumber(vIndtot))
XResultSetValue(vRSKey, "ActHard", @ToNumber(vTotpmt))
next
XResultSetClose(vRSKey)
}



[/code]

  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: "posting" to subform
Reply #1 - Oct 29th, 2010 at 3:05am
Print Post Print Post  
Try putting the following code somewhere near the top of yours. (Must, at least, be before the loop that changes the subrecords.)

Code
Select All
// Must put focus on last subrecord, or else it may not update properly when changes are made.
FormResultSetCurrentPosition("Detail", @FormResultSetTotal("Detail")) 


The data in the subrecords is probably being changed, but just isn't being drawn in the cells. If you were to click on the subform rows, they would probably update to show the changes. Using the code above to put focus in the last subrecord should make it redraw all of the cells when they are updated with XResultSetValue. (Using ForceRedraw won't work here.)


BTW, did you know that you can use @XResultSetForm("Detail") to get the current subform records that you see on the current parent? This is a bit of a shortcut from what you are currently using.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: "posting" to subform
Reply #2 - Oct 29th, 2010 at 1:12pm
Print Post Print Post  
You should not use XResultSet to write to records that are currently on your screen. Use FormFieldValue and the associated family of commands instead.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
CapitalG
Full Member
Members
***
Offline



Posts: 143
Location: Phoenix, Arizona
Joined: Mar 4th, 2003
Re: "posting" to subform
Reply #3 - Oct 29th, 2010 at 2:44pm
Print Post Print Post  
Thank you both for the helpful info.  With the following code it worked just as expected.

Thanks again.
Code
Select All
#include "sbasic_include.sbas"

var vKey as int
var vNoOfRecords as Double
var vloop as Double
var vTotpmt as Double
var vIndpercnt as Double
var vLE2 as Double
var vLE3 as Double
var vLE4 as Double
var vActSoft as Double
var vActHard as Double
var vSoft as Double
var vHard as Double
var vIndtot as double


vLE2 = LE2
vLE3 = LE3
vActSoft = Act.Soft
vActHard = Act.Hard
vKey = ParID

vNoOfRecords = @FormResultSetTotal("Detail")
for vLoop = 1 to vNoOfRecords
FormResultSetCurrentPosition("Detail", vLoop)
vSoft = @FormFieldValue("Data!Detail", "Soft", vLoop)
vHard = @FormFieldValue("Data!Detail", "Hard", vLoop)
vIndpercnt = vSoft/vLE2
vLE4 = vHard/VLE3
vIndtot = vIndpercnt * vActSoft
vTotpmt = vLE4 * vActHard
FormFieldValue("Detail", "ActSoft", vLoop, @ToNumber(vIndtot))
FormFieldValue("Detail", "ActHard", vLoop, @ToNumber(vTotpmt))
next
 


  
Back to top
 
IP Logged