LabelVision Classic: Technical Notes

Using LCALC for Calculations
This technical note provides detailed information about LCALC.EXE, a DOS utility included with LabelVision Professional version 2.3 or later. LCALC can be called from within LabelVision applications to perform calculations on data. For example, suppose you want to print identical box labels for all pallets in a shipment. Each pallet holds 20 boxes, and you want to have an operator enter the number of pallets at print time. In this case, you would call LCALC to multiply the number of pallets entered by the operator by 20 to calculate the total number of box labels to print.

LCALC comes with a help screen, accessed by typing "LCALC /?" at the DOS command line. The help screen displays all available program options, arguments, and a description of the functions and operators that can be included in an LCALC calculation.

Using LCALC in an Application
LCALC is added to an application as a "Run a DOS program" item. Add this item to your application below application items that provide data necessary for the calculation. The PROGRAM specifies LCALC and the output file name, and the remaining ARGUMENTS are the components of the calculation. The calculation result will be stored in an output text file which will later be used as a data source for your label or other application item(s).

In our example, the first application item will be "Input from Operator" with a number type field named "Num_Pallets" which will ask the operator for the number of pallets. The second application item will be "Run a DOS program". In the "Edit DOS Program Item" dialog box, set the Program to be a constant with the value "LCALC /O calc.txt", where calc.txt is the output file where the LCALC results will be stored, and can be any name. The first Argument would be the field "No_Pallets" and the second argument would be the constant text "*20". Be sure to check the "Put quotes around arguments" option.

For the next application item, add a "Single record per file" Text File item. For the text file name, type the LCALC output file (calc.txt in the above example). Add a single field, and change its name from "Field-1" to "Result." This field holds the results of your calculation, and can be used in any subsequent application item.

The last application item will be a "Label". In the "Edit Label" dialog box press the "Set Copies" button to select the "Result" field in the calc.txt text file.

LCALC Calculations
The arguments you pass to LCALC make up an algebraic expression, containing constants and data from field sources. LCALC evaluates everything left-to-right, so be sure to use parenthesis where necessary. For example, 2+3*5 produces 25 [ (2+3)*5 ], not 17 [ 2 + (3*5) ]. Double quotes (") are completely ignored by LCALC (because they might be added automatically to every argument). Use single quotes (') to surround strings which contain spaces or non-alphabetic characters.

LCALC also includes the functions SUM, AVG, RIGHT, etc. A short description of these functions can be viewed by typing "LCALC /?" at the DOS command line.

Input From a File
LCALC is also capable of taking its input from a file. This feature is useful if your calculation exceeds the DOS command line limit (128 characters). It's also useful if you want to build up your calculation piece-by-piece, like when you need to add up values from a database. Such an application is best explained by example. The following application computes the total weight of an order by multiplying the quantity field times the weight field of parts for a given order in the line-item database.

Application Item Parameters/Definition Notes
Run a DOS Program LOG /o CALC.IN /R Initialize the log file.
dBase LINEITEM.DBF ORDER_NO = 1234 An example that selects order number 1234. You will typically select based on cross-reference or input from operator.
Run a DOS Program LOG /o CALC.IN "(" QUANTITY "*" WEIGHT ")+" QUANTITY and WEIGHT are fields from LINEITEM. "*" and ")+"are constant values.
Run a DOS Program (must be un-indented to the left) LCALC /i CALC.IN /o CALC.OUT Perform the calculation after all records in the database have been processed.
Text File (Single Record per file) Filename: CALC.OUT. Have a single field called TotalWeight Read the calculated data back in.
Print Label Use TotalWeight in a field on the label  

Speeding up printing
Normally, when the Print Program calls a DOS program, it "swaps" itself out of DOS memory (either to disk or to EMS memory), which frees up all but about 5K of DOS memory for the DOS program. This swapping is necessary when calling any DOS program that requires more than about 50K or so of memory.

This swapping does take time. Applications which run a small DOS program will run faster if you disable swapping. The time savings is especially significant if your application repeatedly runs the DOS program..

To disable swapping, specify the /X NOSWAP option on the command line when you call the print program. If you access your application from a LabelVision menu, simply add "/X NOSWAP" to the beginning of the "Options" box in the Menu Editor’s "Define Action" dialog box.

If you start your application from a DOS batch file, add "/X NOSWAP" to the LPRINT command line. The final line will be something like that shown below:

    LPRINT /X NOSWAP /L myapp

Send mail to
webmaster@labelvision.com with questions or comments about this website.
Copyright© 2014 Flexible Information Systems, Inc.