Page Index Toggle Pages: [1] 2  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) ThrowFocus loop (Read 2195 times)
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
ThrowFocus loop
May 22nd, 2009 at 3:21pm
Print Post Print Post  
In the interest of learning, why does the combination of ThrowFocus and @Msgbox cause repeats in the same {} ?

Or maybe I should word it, how do I structure the above so that it does not cause repeats in the same { } ?
  

Larry
Back to top
IP Logged
 
Ben
Lantica Support
*****
Offline



Posts: 218
Joined: Apr 7th, 2005
Re: ThrowFocus loop
Reply #1 - May 22nd, 2009 at 5:22pm
Print Post Print Post  
lksseven,
Please post the section of programming that you are having trouble with.
  
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: ThrowFocus loop
Reply #2 - May 22nd, 2009 at 5:28pm
Print Post Print Post  
Hi Ben,

I'll find some and post it.   Mine is just a general observation that I have run into on several occasions and in those instances I just rearranged stuff to avoid the 'threepeat'.

Thanks!
  

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



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: ThrowFocus loop
Reply #3 - May 22nd, 2009 at 7:15pm
Print Post Print Post  
Ben,

the following code causes the Message Box to pop up three times ...

              else
               {
                @Msgbox("cannot save a record without an Item Num.  Please fix or delete this record.","","")
                ThrowFocus(ItemNum)
               }
  

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


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: ThrowFocus loop
Reply #4 - May 22nd, 2009 at 8:42pm
Print Post Print Post  
In which element/event does that code appear?
  

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


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: ThrowFocus loop
Reply #5 - May 23rd, 2009 at 12:43am
Print Post Print Post  
The problem may actually be in the line above "else".  If this programming is in the ItemNumber element, then some condition, noted above, may not exist cauding this section of code to run again. 

Can you insert some WriteLns in the code to trace what is actually happening?
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: ThrowFocus loop
Reply #6 - May 23rd, 2009 at 6:48pm
Print Post Print Post  
Here is a better example (on element change)...

   If (Saved <> "Y")
     {
      ThrowFocus(ItemCost)
     }
      else
       {
        ThrowFocus(AddNewItem)
        Writeln("The Last line item has been placed.", "Unless you wish to add another line item,", "Close this window and then Press the 'Save this PO after Placing' on main PO form")

        //@Msgbox("The Last line item has been placed.", "Unless you wish to add another line item,", "Press the 'Save this PO after Placing' on main PO form")
       }

It was giving me a repeat of the msgbox, so I commented out the msgbox line, and inserted a Writeln message instead.  It's still repeating (see WriteLn message below), but only one window to acknowledge at least.

The Last line item has been placed.
Unless you wish to add another line item,
Close this window and then Press the 'Save this PO after Placing' on main PO form
The Last line item has been placed.
Unless you wish to add another line item,
Close this window and then Press the 'Save this PO after Placing' on main PO form
  

Larry
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: ThrowFocus loop
Reply #7 - May 24th, 2009 at 1:06am
Print Post Print Post  
You provided the event: Quote:
Here is a better example (on element change)...
, but not the element name.

This Msg ran because Saved was = "Y".  I see nothing that changes Saved, so it is still = "Y", so it will run again.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: ThrowFocus loop
Reply #8 - May 24th, 2009 at 2:32am
Print Post Print Post  
@MsgBox tries very hard to put focus back in the element where you were when it pops up after the message is dismissed. This appears to be fighting with ThrowFocus trying to force focus to go elsewhere.
  

- 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: ThrowFocus loop
Reply #9 - May 24th, 2009 at 5:12am
Print Post Print Post  
Hammer,

Thank you for the 'inside' on @MsgBox's druthers be to return to the triggering field.  I will try to abide its preferences.

The code appears in element PlacedYN:Shockedn element change.  It is the trigger field that - if it contains a "Y" - updates inventory record and also finds all relevant Pricing records and updates pricing based upon cost change, then places a "Y" in the Saved element (for visual reference to the user) and then goes either to ItemCost or AddNewItem, depending on whether or not it's the last line item to be placed.

Bob,
    I don't understand why @MsgBox would run again.  It's not a loop (at least not on purpose!).  

"Saved" is the name of the element (you're right, that wasn't clear).  If "Y" is not the value in "Saved", then I want the focus to go to "ItemCost".  But if "Y" is the value in "Saved", then I want the focus to be thrown to "AddNewItem".
« Last Edit: May 24th, 2009 at 9:21pm by lksseven »  

Larry
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: ThrowFocus loop
Reply #10 - May 25th, 2009 at 12:42am
Print Post Print Post  
Have you tried using a Loiter after the Msg and before the ThrowFocus?
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: ThrowFocus loop
Reply #11 - May 25th, 2009 at 3:11am
Print Post Print Post  
No, but I will try it right now.

I tried it, but it still gave me a double message box.  That got me thinking that I may have a more indepth problem with the logic of my code (and not just a problem with Throwfocus and @MsgBox), and it seems that I was correct.  
I went back in and fixed my logical flow error, but the end of the code still gives me a double line entry on my Writeln message.

PS - Below I'm adding the entire code for this 'on element change'.  It's a lot of code (my apologies!), but perhaps my error is further up the line.  The execution of this one element is really my main lynchpin for abandoning Q&A (the ability to automatically in real time update Pricing records based upon changes in ItemCost).
***********************************
[size=8]//  updates Inventory record to reflect cost changes, POdate, PO#, VendorID.
//  also, if cost has changed, then Pricing records are updated automatically, utilizing different mechanisms depending on whether cost went up or down.

#include "sbasic_include.sbas"
//this group of var's is for XResultSet to get Inventory current fields to post to Inventory Last fields
var vLastCost as money
var vLastPOQty as double
var vLastPOAvail as string
var vLastPONum as string
var vLastPODate as date
var vLastVendor as string

//this group of var's is for XResultSet to post data to Inventory record
var vRS as Int
var vItemCCost as Money
var vItemqQty as double
var vItemAvail as string
var vPONum as string
var vPODate as date
var vVendor as string

// this group is for the writing of line items ordered to the SummaryView MultiLine field
var vTemp as Int
var vLine as String
var vItemNum as String
var vItemQty as String
var vItemUoM as String
var vItemDesc as String
var vSumView as String
var vSumView1 as String

// this group is for Pricing - if cost has changed, find all records with this ItemNum
// and update Pricing!ClientPrice using new POLines!ItemCost and Pricing!Margin
var vPprice as double
var vMarg as double
var vRecordTotal as int
var vPM as string
var vLoop as int
var vPriceDate as date
var vlastPcost as double
var vlastPclientprice as double
var vlastPpricedate as date
var vlastPponum as string
var vlastPmargin as double
var vItemCustPriceID as string
var vEmail as int
var vPAN as string
var vCostShadow as money

// this group is for figuring pricing if Margin/Normal client and also if Protected/Contract client
var vNC as money
var vOC as money
var vDC as double
var vCSP as double
var vPSP as double
var vPrice as money
var vNmarg as double
var vPrice4 as money
var vPrice5 as money
var vMarg4 as double
var vMarg5 as double

var vCount as Int
var vLoopT as Int
var vTotal as Double
var vPOTotal as Double


vItemNum = ItemNum
vItemQty = ItemQty
vItemUoM = ItemUoM
vItemDesc = ItemDesc
vPAN = "Y"
vCostShadow = CostShadow
vItemCCost = ItemCost


// Prevent Extend Mode
NotifyForm(7)

If (@Mode() < 2) and (@IsBlank(POLinesYN) = 0) and (POLinesYN <> "Y")
{
   WriteLN("Only a 'Y' is permitted in this Placed? field.","Close this window and try again.")
   Clear(POLinesYN)
   ThrowFocus(POLinesYN)
}
  // ELSE

 

If ((@Mode() = 1) or (@Mode() = 0)) and (POLinesYN = "Y") and (ItemCost = CostShadow)
{
  // this XResult section below posts line item data to Inventory record
  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 field info in Inventory in order to post it to the 'Last' fields in Inventory
     vLastCost = @XResultSetValue(vRS, "ItemCurrentCost")
     vLastPOQty = @XResultSetValue(vRS, "CurrentPOQty")
     vLastPOAvail = @XResultSetValue(vRS, "CurrentPOAvail")
     vLastPONum = @XResultSetValue(vRS, "CurrentPONum")
     vLastPODate = @XResultSetValue(vRS, "CurrentPODate")
     vLastVendor = @XResultSetValue(vRS, "CurrentVendor")
          //   Get the current relevant field info from POLines to post in Current fields in Inventory
     vItemCCost = ItemCost
     vItemqQty = ItemQty
     vItemAvail = ItemAvail
     vPONum = PONum
     vPODate = @FormFieldValue("Purch", "PODate", 0)
     vVendor = @FormFieldvalue("Purch", "VendorID", 0)
                             
     // Post/Set the existing PO data in Inventory from 'current' to 'last'
     XResultSetValue(vRS, "LastCost", vLastCost)
     XResultSetValue(vRS, "LastPOQty", vLastPOQty)
     XResultSetValue(vRS, "LastPOAvail", vLastPOAvail)
     XResultSetValue(vRS, "LastPONum", vLastPONum)
     XResultSetValue(vRS, "LastPODate", vLastPODate)
     XResultSetValue(vRS, "LastVendor", vLastVendor)

     // Post/Set the data in POLines to the 'current' data fields in Inventory
     XResultSetValue(vRS, "ItemCurrentCost", vItemCCost)
     XResultSetValue(vRS, "CurrentPOQty", vItemqQty)
     XResultSetValue(vRS, "CurrentPOAvail", vItemAvail)
     XResultSetValue(vRS, "CurrentPONum", vPONum)
     XResultSetValue(vRS, "CurrentPODate", vPODate)
     XResultSetValue(vRS, "CurrentVendor", vVendor)
     }
     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 Inventory Xresult set

                 // this below section is for POTotals and Saving when the Record ItemCost = CostShadow


    // this next section is for the Summary field

    vLine = vItemNum + " ** " +  vItemQty + " " + vItemUoM + " ** " +  vItemDesc + @Newline() + "==========" + @Newline()
    POLstr = vLine
    FormFieldValue("POLines", "Saved", 0, 1)
    @Save
    If (Saved <> "Y")
     {
      ThrowFocus(ItemCost)
     }
    If (Saved = "Y")
     
     {
        //ThrowFocus(AddNewItem)
        vTotal = 0
        vCount = @FormResultSetTotal("POLines")

        vLoopT = 1
        While vLoopT <= vCount
     
         {
          vTotal += @ToNumber(@FormFieldValue("POLines", "LineItemTotal", vLoopT))
          vLoopT += 1
         }

        If vTotal > 0
         {
          FormFieldvalue("Purch", "POTotal", 0, vTotal)
         }

        Writeln("The Last line item has been placed.  Unless you wish to add another line item, close this window and then Press the 'Save this PO after Placing' on main PO form")
        //ThrowFocus(AddNewItem)
        //@Msgbox("The Last line item has been placed.", "Unless you wish to add another line item,", "Press the 'Save this PO after Placing' on main PO form")
     }
  }            // this closes the Inventory calcs of If ItemCost = CostShadow section

   Else
   {
    @MsgBox("Error: Cannot open XResultSet.", "", "")
   }

}            // this closes the #1 Section - If ItemCost = CostShadow


     // this next section is for the Inventory calc and also the Pricing database calcs in the event that a new ItemCost
     // is different than the previous ItemCost


If ((@Mode() = 1) or (@Mode() = 0)) and (POLinesYN = "Y") and (ItemCost <> CostShadow)
{
  // this XResult section below posts line item data to Inventory record
  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 field info in Inventory in order to post it to the 'Last' fields in Inventory
     vLastCost = @XResultSetValue(vRS, "ItemCurrentCost")
     vLastPOQty = @XResultSetValue(vRS, "CurrentPOQty")
     vLastPOAvail = @XResultSetValue(vRS, "CurrentPOAvail")
     vLastPONum = @XResultSetValue(vRS, "CurrentPONum")
     vLastPODate = @XResultSetValue(vRS, "CurrentPODate")
     vLastVendor = @XResultSetValue(vRS, "CurrentVendor")
          //   Get the current relevant field info from POLines to post in Current fields in Inventory
     vItemCCost = ItemCost
     vItemqQty = ItemQty
     vItemAvail = ItemAvail
     vPONum = PONum
     vPODate = @FormFieldValue("Purch", "PODate", 0)
     vVendor = @FormFieldvalue("Purch", "VendorID", 0)
                             
     // Post/Set the existing PO data in Inventory from 'current' to 'last'
     XResultSetValue(vRS, "LastCost", vLastCost)
     XResultSetValue(vRS, "LastPOQty", vLastPOQty)
     XResultSetValue(vRS, "LastPOAvail", vLastPOAvail)
     XResultSetValue(vRS, "LastPONum", vLastPONum)
     XResultSetValue(vRS, "LastPODate", vLastPODate)
     XResultSetValue(vRS, "LastVendor", vLastVendor)

     // Post/Set the data in POLines to the 'current' data fields in Inventory
     XResultSetValue(vRS, "ItemCurrentCost", vItemCCost)
     XResultSetValue(vRS, "CurrentPOQty", vItemqQty)
     XResultSetValue(vRS, "CurrentPOAvail", vItemAvail)
     XResultSetValue(vRS, "CurrentPONum", vPONum)
     XResultSetValue(vRS, "CurrentPODate", vPODate)
     XResultSetValue(vRS, "CurrentVendor", vVendor)
     }
      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 Inventory Xresult set
  }


  vRS = @XResultSetSearch(@FN, "pricing", SEARCH_MODE_AND,SEARCH_SYNTAX_QA, "!ItemNum=" + @Str(ItemNum))
  If vRS > -1
  {
    vRecordTotal = @XResultSetTotal(vRS)
    vPODate = @FormFieldValue("Purch", "PODate", 0)
    for vLoop = 1 to vRecordTotal
     XResultSetCurrentPosition(vRS, vLoop)
     vItemCCost = ItemCost
       vCostShadow = CostShadow
     vMarg = @XResultSetValue(vRS, "Margin")
       vPprice = @XResultSetValue(vRS, "ClientPrice")
     vPM = @XResultSetValue(vRS, "PriceOrMargin")
     vPODate = @FormFieldValue("Purch", "PODate", 0)
       vPONum = @FormFieldValue("Purch", "PONum", 0)
     vItemCustPriceID = @XResultSetValue(vRS, "ItemCustPriceID")
     //Confirm I can change the Pricing record
     If @XResultSetLocked(vRS) = 1
     {
       @MsgBox("Error: Pricing record is locked by another user.","","")
     }
     else
     {
       If vPM = "M" and (vItemCCost > vCostShadow)  //new cost is more then old cost, margin and normal clients have pricing automatically adjusted, based upon ItemCost
       {
                     // this section takes current info in Pricing and plugs it into Last Pricing fields

         vlastPclientprice = @XResultSetValue(vRS, "ClientPrice")
         vlastPmargin = @XResultSetValue(vRS, "Margin")
         vlastPcost = @XResultSetValue(vRS, "Cost")
         vlastPpricedate = @XResultSetValue(vRS, "PriceDate")
           vlastPponum = @XResultSetValue(vRS, "PONum")
         vPODate = @FormFieldValue("Purch", "PODate", 0)
           vPONum = @FormFieldValue("Purch", "PONum", 0)

         XResultSetValue(vRS, "LastClientPrice", vlastPclientprice)
         XResultSetValue(vRS, "LastMargin", vlastPmargin)
         XResultSetValue(vRS, "LastCost", vlastPcost)
         XResultSetValue(vRS, "LastPriceDate", vlastPpricedate)
           XResultSetValue(vRS, "LastPONum", vlastPponum)
           

                   // this section takes current cost and calcs new pricing data/margins/costs

         vMarg = (vMarg * 1.03)
         XResultSetValue(vRS, "Cost", vItemCCost)
           vPprice = (vItemCCost/(1-vMarg))
         XResultSetValue(vRS, "ClientPrice", vPprice)
           XResultSetValue(vRS, "Margin", vMarg)
         XResultSetValue(vRS, "PriceDate", vPODate)
           XResultSetValue(vRS, "PONum", vPONum)
           XResultSetValue(vRS, "ItemDesc", vItemDesc)
       }
         
         If vPM = "M" and (vItemCCost < vCostShadow)  //new cost is less than old cost, margin and normal clients have pricing automatically adjusted, based upon ItemCost
       {
                     // this section takes current info in Pricing and plugs it into Last Pricing fields

         vlastPclientprice = @XResultSetValue(vRS, "ClientPrice")
         vlastPmargin = @XResultSetValue(vRS, "Margin")
         vlastPcost = @XResultSetValue(vRS, "Cost")
         vlastPpricedate = @XResultSetValue(vRS, "PriceDate")
         vPODate = @FormFieldValue("Purch", "PODate", 0)
           vPONum = @FormFieldValue("Purch", "PONum", 0)

         XResultSetValue(vRS, "LastClientPrice", vlastPclientprice)
         XResultSetValue(vRS, "LastMargin", vlastPmargin)
         XResultSetValue(vRS, "LastCost", vlastPcost)
         XResultSetValue(vRS, "LastPriceDate", vlastPpricedate)
           XResultSetValue(vRS, "LastPONum", vlastPponum)

                   // this section takes current cost and calcs new pricing data/margins/costs

         vNC = vItemCCost
           vOC = vCostShadow
           vDC = (vOC - vNC)
         vCSP = vDC/vOC
           vPSP = (vCSP * .4)
           vPprice = (vPprice * (1 - vPSP))
         vNmarg = ((vPprice - vNC)/vPprice)
         XResultSetValue(vRS, "Cost", vNC)
           XResultSetValue(vRS, "ClientPrice", vPprice)
           XResultSetValue(vRS, "Margin", vNmarg)
         XResultSetValue(vRS, "PriceDate", vPODate)
           XResultSetValue(vRS, "PONum", vPONum)
           XResultSetValue(vRS, "ItemDesc", vItemDesc)
       }


       If vPM = "P" and (ItemCost < CostShadow)  // Protected clients - costs and dates and margin get updated, but not pricing - decision maker
                                                   // is notified of these Price Attention Needed accounts at the end of the day
       { 
                     // this section puts current Price info into Last Price fields, updates cost, date, new margin, NoteField, but not ClientPrice

         vPrice4 = @XResultSetValue(vRS, "ClientPrice")
         vlastPmargin = @XResultSetValue(vRS, "Margin")
         vlastPcost = @XResultSetValue(vRS, "Cost")
         // vlastPpricedate = @XResultSetValue(vRS, "PriceDate")
           vlastPponum = @XResultSetValue(vRS, "PONum")
         vPODate = @FormFieldValue("Purch", "PODate", 0)
         XResultSetValue(vRS, "LastMargin", vlastPmargin)
         XResultSetValue(vRS, "LastCost", vlastPcost)
         // XResultSetValue(vRS, "LastPriceDate", vlastPpricedate)
           XResultSetValue(vRS, "LastPONum", vlastPponum)
     

                 // this section puts new cost, calcs new marg and plugs in, and inserts message in PricingNoteField

         XResultSetValue(vRS, "Cost", vItemCCost)
           vMarg4 = ((vPrice4 - vItemCCost)/vPrice4)
           XResultSetValue(vRS, "Margin", vMarg4)
           XResultSetValue(vRS, "PONum", vPONum)
           XResultSetValue(vRS, "ItemDesc", vItemDesc)
         XResultSetValue(vRS, "PricingNoteField", ("Cost went down to " + @str(vItemCCost) + " on " + vPODate))
       }

         If vPM = "P" and (vItemCCost > vCostShadow) // Protected clients - costs and dates get updated, but not pricing and margin -
                                         // decision maker is notified of these Price Attention Needed accounts at the end of the day
                                         // right now via email, but in production it will call a Report that lists the Items,
                                         // old cost, new cost, and Pricing records for each Item
       { 
         // this section puts current Price info into Last Price fields, updates cost, date, new margin, NoteField, but not ClientPrice

                 // this section reads the data it needs and defines variables

           vPrice5 = @XResultSetValue(vRS, "ClientPrice")
         vlastPmargin = @XResultSetValue(vRS, "Margin")
         vlastPcost = @XResultSetValue(vRS, "Cost")
         vlastPpricedate = @XResultSetValue(vRS, "PriceDate")
           vlastPponum = @XResultSetValue(vRS, "PONum")
         vPODate = @FormFieldValue("Purch", "PODate", 0)
           vPONum = @FormFieldValue("Purch", "PONum", 0)

                 // this section plugs in current pricing data into "previous" pricing data

         XResultSetValue(vRS, "LastMargin", vlastPmargin)
         XResultSetValue(vRS, "LastCost", vlastPcost)
         // XResultSetValue(vRS, "LastPriceDate", vlastPpricedate)
           XResultSetValue(vRS, "LastPONum", vlastPponum)

                 // this section updates cost, margin, NoteField, and prints a page that cost has gone up on a Protected Pricing Record

         XResultSetValue(vRS, "Cost", vItemCCost)
           vMarg5 = ((vPrice5 - vItemCCost)/vPrice5)
           XResultSetValue(vRS, "Margin", vMarg5)
         XResultSetValue(vRS, "PricingNoteField", ("Cost went up to " + @str(vItemCCost) + " on " + vPODate))
         // XResultSetValue(vRS, "PriceDate", vPODate)
           XResultSetValue(vRS, "PONum", vPONum)
           XResultSetValue(vRS, "ItemDesc", vItemDesc)
         //vEmail = @sendmail("smtp.wordcom.com", "PriceActionNeeded","lseale@wordcom.com","lseale@wordcom.com","lksseven@gmail.co
m","","Item cost on " + vItemCustPriceID + " went up to " + @STR(vItemCCost))
           //NewPage(850, 1100)
           //PrintString("For this Price Proteced client record " + vItemCustPriceID + ", Item Cost has increase from " + vCostShadow + " to " + vItemCCost + ".  Price analysis is needed.", 12, 24, 0, " ARIAL", 12, 0)
           //FinishPage()
         XResultSetValue(vRS, "PAN", vPAN)
        }       
        }      // end of the Else calc
       next
       XResultSetClose(vRS)
        
                 // below is the continuation of first If POLinesYN = "Y" condition.  It should calc running POTotal
                 // and then save the record, and then go to next record, or if last record, then Write Message
                 // that this was the last record on the PO


    // this next section is for the Summary field

    vLine = vItemNum + " ** " +  vItemQty + " " + vItemUoM + " ** " +  vItemDesc + @Newline() + "==========" + @Newline()
    POLstr = vLine
    FormFieldValue("POLines", "Saved", 0, 1)
    @Save
    If (Saved <> "Y")
     {
      ThrowFocus(ItemCost)
     }
    If (Saved = "Y")
     {
        //ThrowFocus(AddNewItem)
        vTotal = 0
        vCount = @FormResultSetTotal("POLines")

        vLoopT = 1
        While vLoopT <= vCount
     
         {
          vTotal += @ToNumber(@FormFieldValue("POLines", "LineItemTotal", vLoopT))
          vLoopT += 1
         }

        If vTotal > 0
         {
          FormFieldvalue("Purch", "POTotal", 0, vTotal)
         }

        Writeln("The Last line item has been placed.  Unless you wish to add another line item, close this window and then Press the 'Save this PO after Placing' on main PO form")
        //ThrowFocus(AddNewItem)
        //@Msgbox("The Last line item has been placed.", "Unless you wish to add another line item,", "Press the 'Save this PO after Placing' on main PO form")
     }
  }            // this closes the Pricing calcs of If ItemCost <> CostShadow section

   Else
   {
    @MsgBox("Error: Cannot open XResultSet.", "", "")
   }

}            // this closes the #2 Section - If ItemCost <> CostShadow[/size]
« Last Edit: May 26th, 2009 at 3:19am by lksseven »  

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



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: ThrowFocus loop
Reply #12 - May 27th, 2009 at 2:02am
Print Post Print Post  
ok, forget about the monster code .... I commented out all except the following three lines ...

    Writeln("Before save")
    @Save
    Writeln("After save")

I used a PO with 2 records.  After the first record posted, the Slate said

Before save
After save

So I closed it out. 

After the second record posted, the slate said

Before save
After save
Before save
After save

The manual says that @Save acts like the F10 key, saving the record and then moving on to the next record, IF THERE IS ONE.   But I have prevented additional records in extend mode at the beginning of this code, so what happens internally after the @Save command if it is the last record?

Would I solve my problem if I put a snippet in there that would ask (before the save command) if it's the last record ... if no, then use @Save,  if yes, then use FormCommit ? 

But I'd like to understand what @Save is doing to cause the 'repeat' when it reaches the last record.
  

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



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: ThrowFocus loop
Reply #13 - May 27th, 2009 at 7:21am
Print Post Print Post  
I achieved a solution with the following condition and subsequent code (apparently the code was being executed twice on the last record - something to do with the @save or FormCommit command, as it didn't execute twice if I didn't save via code the last record.  I couldn't figure out where my flawed logic is, so I added a @IsBlank(Saved) condition that is true the first time through, but a Y is added to Saved element during the processing, so the condition is not true after the first pass, and thus no second pass is executed.

If ((@Mode() = 1) or (@Mode() = 0)) and (POLinesYN = "Y") and (ItemCost = CostShadow)
{
If @IsBlank(Saved)
  {
.......

vCount = @FormResultSetTotal("POLines")
    vPos = @FormResultSetCurrentPosition("POLines")
    If vPos < vCount
     {
      @Save
      ThrowFocus(ItemCost)
     }
      else
       {
        FormCommit("")
        Writeln("The Last line item has been placed.
       }
  

Larry
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: ThrowFocus loop
Reply #14 - May 27th, 2009 at 2:16pm
Print Post Print Post  
Good detective work lksseven.  Cool

Thanks for sharing the solution with us.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send Topic Send Topic Print Print