Subject Re: requery problem (semi reason)
From Mervyn Bick <invalid@invalid.invalid>
Date Thu, 9 Jan 2020 13:39:09 +0200
Newsgroups dbase.getting-started

On 09/01/2020 10:31, Mervyn Bick wrote:

> I can't tell why but at least I can suggest a way to fix it.

Let's start with a couple of cliches. "If it works, it's not wrong." and
"Don't change a winning team.".  :-)  But...

Your code can be simplified by one small change to your workflow.  It
may be urban myth but Henry Ford is purported to have said he made his
first petrol engine with one cylinder. If anything went wrong he knew
exactly where to start looking.  The simpler the code, the less to go wrong.

Instead of using 5 separate queries and a raft of code to calculate the
count and total for the various values for the categories saved in the
sauc field of the master table it can all be done in one query.  This
will allow you to get rid of the queries master2 to master6.

   this.MASTER_TOTALS = new QUERY(this)
    with (this.MASTER_TOTALS)
       left = -58.0
       top = 13.0
       database = form.database1
       sql = 'select sauc,count(sell) sell_count,sum(sell) sell_sum from
"master" group by sauc'
       active = true

As an aside, if you enter    select sauc,count(sell)
sell_count,sum(sell) sell_sum from "master" group by sauc    as one line
in the command panel and then enter  browse   you will be able to see
the rowset.  When you've done enter  use  to close the workarea.

Your queries master2 to master6 didn't limit records to a range of dates
so I haven't done that here either.  If you need to do this you can add
a WHERE clause before the GROUP BY clause.

It is a good idea to set the when event handler for each entryfield to
false when one is displaying calculated values.  A codeblock works
perfectly.  This prevents the user from changing the values accidentally.

    this.ENTRYFIELD1 = new ENTRYFIELD(this)
    with (this.ENTRYFIELD1)
       height = 1.0
       left = 23.0
       top = 8.0
       width = 8.0
       value = 0
       when = {||false}

Now your code can be simplified.  Because the function doesn't actually
calculate anything let's use something else that makes more sense.

   function form_onOpen()
     set procedure to test.pop additive
     form.popupMenu := new testpopup(form,"testPOPUP")

   function form_onGotFocus()

   function display_totals
      //first reset display in case there are no values for
      //a given value of sauc after an update. e.g no values
      //for sauc = 'X' left in the master table.
      //Without a reset the old values would remain as the
      //requery for master_totals would drop the entry for
      //sauc = 'X'.
      for n = 1 to 9 step 2
         cmd = 'form.entryfield'+n+',value = 0'
      for n = 2 to 10 step 2
         cmd = 'form.entryfield'+n+',value = 0.00'
      do while not form.master_totals.rowset.endofset
         if sauc = 'X'
            form.entryfield1.value = sell_count
            form.entryfield2.value = sell_sum
         elseif sauc = 'T'
            form.entryfield3.value = sell_count
            form.entryfield4.value = sell_sum
         elseif sauc = 'Y'
            form.entryfield5.value = sell_count
            form.entryfield6.value = sell_sum
         elseif sauc = 'Z'
            form.entryfield7.value = sell_count
            form.entryfield8.value = sell_sum
         elseif sauc = 'E'
            form.entryfield9.value = sell_count
            form.entryfield10.value = sell_sum