Normal Topic XResultSetValue - ouch (Read 760 times)
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
XResultSetValue - ouch
Mar 5th, 2009 at 7:01am
Print Post Print Post  
Aspirin time .... I have two db (POLines and Inventory).  I want to post the current POLines!ItemCost value into Inventory!ItemCurrentCost .

I can do it with XPost ...  XPOST(@fn, ItemNum, "Inventory!ItemNum", ItemCost, "ItemCurrentCost", "").

But am trying to learn how to use XResultSetValue code.  I tried to borrow from a previous thread, but my recurring result is always a value of 0.000 in the target Inventory!ItemCurrentCost, instead of $28.00.

Could someone give me a boot in the right direction?  Many thanks!

#include "sbasic_include.sbas"
var vRS as Int
var vItemCCost as Money

    If ((@Mode() = 1) or (@Mode() = 0)) and (@isBlank(POLinesYN) = 0)
     {
           vRS = @XResultSetSearch(@FN, "Inventory", SEARCH_MODE_AND,SEARCH_SYNTAX_QA, "!ItemNum=" + @Str(ItemNum))
           If vRS > -1
           {
                 //Confirm exactly one matching record
                 If @XResultSetTotal(vRS) = 1
                 {
                       //Confirm I can change the Inventory record
                       If @XResultSetLocked(vRS) = 0
                       {
                             // Get the current ItemCost from POLines
                             vItemCCost = @ToMoney(@XResultSetValue(vRS, "ItemCost"))
                             
                             // Post/Set the new POLines!ItemCost value to Inventory!ItemCurrentCost
                             XResultSetValue(vRS, "ItemCurrentCost", vItemCCost)
                       }
                       Else
                       {
                             @MsgBox("Error: Inventory record is locked by another user.","","")
                       }
                 }
                 Else
                 {
                       @MsgBox("Error: There must be only one matching Inventory record.", "", "")
                 }
                 XResultSetClose(vRS)      //Close the result set
           }
           Else
           {
                 @MsgBox("Error: Cannot open XResultSet.", "", "")
           }
     }
  

Larry
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: XResultSetValue - ouch
Reply #1 - Mar 5th, 2009 at 2:46pm
Print Post Print Post  

This: vItemCCost = @ToMoney(@XResultSetValue(vRS, "ItemCost"))
Does not do this: // Get the current ItemCost from POLines

vRS is looking at the record you got from Inventory with @XResultSetSearch. The line of code above sets vItemCCost to the ItemCost in the Inventory record, not POLines.

To test the code, hardcode vItemCCost and see if it works.
vItemCCost = 10

If that does not work, you have a misspelled field name or suchlike. If it does work, get the correct value from POLines.
vItemCCost = ItemCost
  

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



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: XResultSetValue - ouch
Reply #2 - Mar 5th, 2009 at 3:27pm
Print Post Print Post  
Thank you!!!  I'll try it as soon as my double vision goes away  Shocked
  

Larry
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: XResultSetValue - ouch
Reply #3 - Mar 5th, 2009 at 5:02pm
Print Post Print Post  
it worked.  Thanks mucho.

(when I told my wife I was up till 1am working on a single bit of code, she shook her head and remarked "Of course you were.  Why ask for directions when you can drive around for 3 hours like a dufus!"    Sigh...
  

Larry
Back to top
IP Logged