Cnt

From BR Wiki
Revision as of 13:42, 12 January 2012 by Mikhail.zheleznov (talk | contribs) (edit)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The CNT internal function returns the number of data items successfully processed by the last I/O statement. When there is an error in a field definition array in INPUT FIELDS, PRINT FIELDS or RINPUT FIELDS statements, CNT will return the number of the last successfully processed element in the error-causing field definition array.

Comments and Examples

When an I/O error occurs, the CNT function is very useful in debugging. Suppose the following program has two arrays of 52 elements each:

00510 READ #2,USING 520: MAT PAYTYPE$,FLAG$,MAT AMT
00520 FORM 52*C 1,N 1,52*N 5.2

Error code 0726 will occur on line 510 above to indicate a conversion error on one of the 103 items being read. As soon as the error occurs, the operator should enter PRINT CNT (or just CNT), and the system will print 52. This means the first 52 items were read successfully and the problem is in the 53rd item. CNT immediately localizes the problem to FLAG$ (which cannot be read with an N 1 format because it is a string variable).

In the following example, CNT is used within a program to redimension an array to the number of elements read:

00010 DIM A(20)
00020 DATA 1,2,3,4,5
00030 READ MAT A EOF 40
00040 MAT A(CNT)

Related Functions

The ERR and LINE functions are also commonly used for debugging.

Technical Considerations

If the current error was not an I/O error, CNT will be irrelevant because it contains information about a previous error.