Normal Topic OnElementChange looping (Read 856 times)
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
OnElementChange looping
Nov 11th, 2009 at 8:59pm
Print Post Print Post  
Orders!SOLines, formview, ItemNum:ShockednElementChange ... If an ItemNum that warrants a suggested alternative, I have a Writeln window notify user of that.  My problem is that the Writeln is writing twice instead of just once, and I can't figure out where my error is.  It triggers on vFlag = 0, and then I've got a vFlag = 2 just before the Writeln code, but it's looping back through and writing twice, even though the vflag shows as a 2 ... first the code (relevant lines in red), then the Writeln result (it's not a problem for the line to be duplicatd, by I want to learn what's not right in my code so I'll know better in other tasks)...

If @Group <> "clients"
{ //a

If ((@Mode() = 0) or (@Mode() = 1)) //and ((ItemNum) <> "AddRookie")      // this code searches for a matching Inventory record and, if found, populating other fields
{ //b

If vFlag = 0
{ //c


If (((ItemNum) <> "AddRookie") and (@IsBlank(ItemNum) = 0) and (ItemNum <> "Stop") and (ItemNum <> "vStop"))
{ //d

 SONum = @FORMFIELDVALUE("Orders","SONum",0)            // this  first section fills in SONum, SODate, ClientID
 SODate = @FormFieldValue("Orders", "SODate", 0)
 SOTime = @FormFieldValue("Orders", "SOTime", 0)
 ClientName = @FormFieldValue("Orders", "ClientName", 0)
 ClientID = @FORMFIELDVALUE("ORDERS","ClientID",0)

 v2ItemNum = @FormFieldValue("SOLines", "ItemNum", 0)
 vRS2 = @XResultSetSearch(@FN, "Inventory", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!ItemNum=" + v2ItemNum)
 
   If @XresultSetTotal(vRS2) = 1                          // if there is exactly one matching record in Inventory, pull data from Inventory into SOLines
        {
                                                         // Get and then plug ItemDesc, Cost, UoM, Cat and issue message box to manually enter Price
       v2ItemDesc = @XResultSetValue(vRS2, "ItemDesc")
       v2ItemUom = @XResultSetValue(vRS2, "ItemUoM")
       v2ItemCost = @XResultSetValue(vRS2, "ItemCurrentCost")
         v2ItemCat = @XResultSetValue(vRS2, "ItemCat")
       v2InternalNote = @XResultSetValue(vRS2, "InternalNote")
       FormFieldValue("SOLines", "ItemDesc", 0, v2ItemDesc)
         FormFieldValue("SOLines", "ItemUoM", 0, v2ItemUoM)
       FormFieldValue("SOLines", "ItemCost", 0, v2ItemCost)
         FormFieldValue("SOLines", "ItemCat", 0, v2ItemCat)

       vQtyAvail = @XResultSetValue(vRS2, "QtyAvail")
       vQtyOnOrder = @XResultSetValue(vRS2, "QtyOnOrder")
         FormFieldValue("", "QtyAvail", 0, vQtyAvail)
         FormFieldValue("", "QtyOnOrder", 0, vQtyOnOrder)

                                                 // the next section finds QtyOnBuild


           v3ItemNum = v2ItemNum
           vRS3 = @XResultSetSearch(@FN, "Purch!POLines", SEARCH_MODE_AND,SEARCH_SYNTAX_QA, "!ItemNum=" + v3ItemNum, "!PODate=" + @Date)
           v3Tot = @XResultSetTotal(vRS3)
           v3Date = @XResultSetValue(vRS3, "PODate")
           v3POYN = @XResultSetValue(vRS3, "POLinesYN")
           v3ItemQty = @XResultSetValue(vRS3, "ItemQty")

                 v3Loop = 0                                                  
                 For v3Loop = 1 to v3Tot
                                       
                       XResultSetCurrentPosition(vRS3, v3Loop)
                       v3POYN = @XResultSetValue(vRS3, "POLinesYN")
                             
                       If v3POYN <> ""
                              {
                                         XResultSetRemoveRecord(vRS3)
                               v3Loop = v3Loop - 1
                               v3Tot = v3Tot - 1                                
                                        }
                       Next
                       
                 v3Loop = 0
                 For v3Loop = 1 to v3Tot

                       XResultSetCurrentPosition(vRS3, v3Loop)
                       v3P = @XResultSetCurrentPosition(vRS3)

                       v3ItemQty = @XResultSetValue(vRS3, "ItemQty")
                       v3QtyOnBuildTotal += @TN(v3ItemQty)

                 Next


           FormFieldValue("", "QtyOnBuild", 0, v3QtyOnBuildTotal)
           XResultSetClose(vRS3)

           Clear(ItemPrice)
           RGBColor(AddThisLineItem, -1, -1, -1, 0, 255, 0)
           
             If vFlag = 0                  // a reminder popup for inventory items where alternatives should be suggested
                 {
                   vFlag = 1
                   If v2InternalNote <> ""
                    {
                      vFlag = 2
                      Writeln(vFlag + " Pay attention to this note!!!!  ... " + v2InternalNote)
                       
                    }
               }
      }

the result ....
2 Pay attention to this note!!!!  ... Would the client like Xerox@ and save over 20% at the same time?
2 Pay attention to this note!!!!  ... Would the client like Xerox@ and save over 20% at the same time?
  

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



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: OnElementChange looping
Reply #1 - Nov 11th, 2009 at 9:34pm
Print Post Print Post  
I found the culprit ... a ThrowFocus(ItemQty) line at the bottom of the code.  I put the ThrowFocus(ItemQty) in the ItemNum:ShockednElementExit , and it seems to have solved the problem.

I obviously do not understand the underpinnings of ThrowFocus - I have more trouble with it than any other seemingly simple concept.  Most of the time ThrowFocus seems to want to make the code loop multiple times.  Is it only in OnElementChange trigger that this occurs?
  

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


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: OnElementChange looping
Reply #2 - Nov 11th, 2009 at 10:59pm
Print Post Print Post  
ThrowFocus and WriteLn can interact in unexpected ways since the WriteLn window pulls focus to itself. Especially if there is also On Element Change / Enter /Exit code in the mix.
  

- 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: OnElementChange looping
Reply #3 - Nov 12th, 2009 at 1:47pm
Print Post Print Post  
that does make sense.  So I wonder, could I obviate the issue by Open Slate - Writeln - Loiter - Close Slate so that the user would see the message for a couple seconds and then it would disappear?
  

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


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: OnElementChange looping
Reply #4 - Nov 12th, 2009 at 1:57pm
Print Post Print Post  
lksseven wrote on Nov 12th, 2009 at 1:47pm:
that does make sense.  So I wonder, could I obviate the issue by Open Slate - Writeln - Loiter - Close Slate so that the user would see the message for a couple seconds and then it would disappear?

That's probably still going to pull and then push focus in a similar way. Perhaps you can collect the message in a variable, then call WriteLn in a different event, after you're done throwing focus around?
  

- 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: OnElementChange looping
Reply #5 - Nov 12th, 2009 at 11:12pm
Print Post Print Post  
"after you're done throwing focus around?"

that's a lyrical turn of phrase. I'll use it.

It reminds me of the commercials lately - is it Google, or Intel, or some other high tech outfit? - about geeky programmers being swamped by groupies and such, with the catchline "our rock stars aren't like your rock stars".  So when your phrase made me laugh, and my wife wanted to know what was so funny, I knew in advance that, when I told her the phrase, she was going to look at me with that look of mildly troubled tolerance ("my mother was right, he really is a bit of a goof").

And I was right ... sigh ...
  

Larry
Back to top
IP Logged