Subject Re: requery problem (semi reason)
From Tony Hughes <tamarak1@bigpond.com>
Date Tue, 21 Jul 2020 19:40:22 -0400
Newsgroups dbase.getting-started

Hi Mervyn,
Thank you for your wonderful help, I have not had time to try as yet but will. One other thing I thought of overnight is Maybe I could save this data to an array, as there are only 3 important elements, and a max of 15 ingredients in any chemical formula - But not sure about the procedure for this. The first step for the batcher is to determine how many of a particular formula he needs to batch. I save this to another dbf, print it then consolidate them all into batch.dbf
I remain very grateful,
Tony Hughes  in Ozzie land ?



Mervyn Bick Wrote:

> On 2020-07-21 06:58, Tony H wrote:
> > I have written the following code and need to "empty Table" after the print is finished - The code included does it all except emptying the table for next printing session. A couple of trial coding at the end but I get errors. I need to change from "query" to exclusive use I think, but not sure how ??
> >
> > Tony h
>
> If code works, it's not wrong. :-)  On the other hand, even if it works,
> it may be possible to improve it.
>
> Firstly, PUBLIC variables have their use but unless there is no other
> way of getting round a problem they should be avoided.  PRIVATE and
> LOCAL variables should be all you will need in an event handler.  And
> probably 9 out of 10 times LOCAL is the way to go.
>
> I assume that 15 is the biggest number of components that will ever be
> in a batch.  Creating 15 sets of variables where you may only need 3 or
> 4 is a waste of both programming effort and memory.  And the 15 Pcode
> public variables are never used. :-(  You use Scode variables in the
> report and these get created "on the fly".
>
> As an aside, any variable generated "on the fly" is PRIVATE.  It is,
> however good programming practice to define variables as PRIVATE even if
> this what they would be by default.
>
> All the data for the report is available in form.batch1.rowset so there
> is no real need to move it out into memory variables for printing.
>
> The code below checks first to see if there are any records to print.
> If there are no records there is nothing to be done and there is no
> point in executing the report code.  If there are records it prints the
> report header and then loops through the rowset printing each record
> that it finds.  The code then attempts to empty batch.dbf.  This will,
> however, fail if the table is open in an other form.
>
> The code has, unfortunately, not been tested but let's sort out problems
> if they arise.
>
> The DO WHILE...ENDDO loop ensures that all records, be there 3 or 15,
> get printed before the program ends.
>
> The customer is always right and if you want the same BatchSize value
> printed on each line of the report then so be it.  Personally, I would
> incorporate the BatchSize in the report heading but your're the customer
> and I'm not. :-)
>
> Watch for line wrap.  If anything except the start and end comments and
> the first line is on the left hand edge after you have copied the code
> and pasted it into your form then those "bits" belong to the end of the
> line above.
>
> ***** Start *****
> function PUSHBUTTON1_onClick()
>     // Print Batch Report for Batcher
>
>     LOCAL FormName,BatchSize
>
>    ingnum = 0 //what is this for?
>    // Set up printer for report on Batch Ingredients
>    form.batch1.rowset.first()
>
>    if form.batch1.rowset.count = 0
>       msgbox('No records to print in batch.dbf','Warning',64)
>    else
>       choosePrinter()
>       _copies=2
>       _peject="None"
>       _plineno=3
>       _pmargin=3
>       ingnum = 3 //? what does this do?
>       set printer on
>    //        msgbox("Printer On")
>       set margin to 10
>
>       FormName = form.batch1.rowset.fields["FormName"].value
>       BatchSize =        form.batch1.rowset.fields["BatchSize"].value
>       //We need these values for the header and the rows of the report
>       fbrf = form.batch1.rowset.fields
>       // fbrf is a shortcut to save typing later and to limit length for
> ? command
>       printjob
>       ?        "                        " + FormName + Date()
>       ?
>       ?
>       ? " Ingredient Amt" + " Stock Code " + " Batch Size "
>       ?
>       ?
>       do while not form.batch1.rowset.endofset //loop through table
>          ?  fbrf["ingrval1"].value Picture "999.999" + "           " +
> fbrf["scode1"].value + "         " + BatchSize
>          form.batch1.rowset.next()
>       enddo
>       endprintjob
>       close printer
>       set printer off
>
>       //If we got this far there were records in batch.dbf. Let's get
> rid of them.
>       //Make the query using batch.dbf inactive
>       form.batch1.active = false
>       _app.databases[ 1 ].emptyTable( "Batch" )
>       //The following will only work if batch.dbf is not open in another
> form
>       use batch exclusive
>       zap
>       use
>       form.batch1.active = true
>       //The rowset is empty but let's leave things as we found them.
>       //As the rowset is empty clicking on the pushbutton now will show the
>       //"No records" message.
>     endif
>     return
> **** End ****
>
> Mervyn.
>
>
>
>
>
>