Subject Re: on open problem
From Charlie <tm@tc.com>
Date Sun, 10 Jun 2018 11:15:05 -0400
Newsgroups dbase.getting-started

Hi Mervyn.. Thanks very much for your help.  I think the pushbutton instead of selchange will solve the problem although might be a little confusing for the user.  My problem wasn't the totals though.  That seems to work fine.  At any rate, I think I will cancel my trip to the asylum!!!!!

Mervyn Bick Wrote:

> On 2018-06-10 2:01 PM, Charlie wrote:
> > Hi.. I'm having a problem with when I open this form I have on_open code.  But what happens is it triggers the the grid selchange code which screws everything up.  Is there something I'm doing in the on open code below that is causing this?  Is there something I can do to prevent this from happening?  Should I be using something other than the grid selchange?  Thanks for your help.
> >
> > The grid selchange is related to the talname table.
> >
> > function form_onOpen()
> >            tcost = 0.00
> >            tsell = 0.00
> >                 //talname = trim(form.talmem1.rowset.fields["talname"].value)
> >                 talname = form.talname1.rowset.fields["lname"].value
> >                 q = form.taldata1.rowset
> >        cnt = 0
> >            do while not q.endofset
> >               z = q.fields["qty"].value * q.fields["cost"].value
> >               x = q.fields["qty"].value * q.fields["sell"].value
> >               cnt = cnt + q.fields["qty"].value
> >           tcost = tcost + z
> >                    tsell = tsell + x
> >                         q.next()
> >                 enddo
> >                 form.entryfield1.value := cnt
> >                 form.entryfield3.value := tcost
> >                 form.entryfield4.value := tsell
> >                 form.entryfieldpart_no1.setfocus()
> >                 q.last()
> >                 form.talname1.rowset.findkey(talname)
> >                 form.talname1.rowset.save()
> >                 form.master1.rowset.save()
> >                 set procedure to test.pop additive
> >                 form.popupMenu := new testpopup(form,"testPOPUP")
> >                 return
> >
>
> I'm not sure I have the "picture" of what you're doing but if if the
> data link for the grid is form.taldata1.rowset then stepping through the
> rowset assigned to q will move the row pointer in the grid.
>
> The grid's onSelchange event fires every time the rowpointer moves.  To
> use the event or not depends on what its event handler does.  If you
> navigate in the grid by clicking on specific rows then the onSelchange
> event is probably a good choice.  If you scan up and down the grid using
> the up and down arrow keys then you probably don't want to use it.  It
> may be better to select a row and then click on a pushbutton to trigger
> the code.
>
> In your code you are not assigning any values to fields in
> form.talname1.rowset or form.master1.rowset so the two save()
> instructions are redundant.
>
> I'm guessing but if you want the total number of items, their total
> cost, and the total selling value for each person the following will do
> the trick.  Place a copy of the teldata table on the form.  In the
> Inspector (or in the sourcecode editor after you've saved the file)
> change the query's sql property to
>
>       sql = 'select talname,sum(qty) as cnt, sum(qty*cost) as tcost,
> sum(qty*sell) as tsell from taldata group by talname'
>
> If you assign the resulting rowset to a grid's data link you will see
> the values for all the customers.  I've assumed tha talname is the filed
> in taldata with the customer name.  If not use the correct field name.
>
>
> Mervyn.
>
>
>
>
>
>
>
>
>
>