Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeEnglishEspañolContact

The text of a manual · part 14 of 26

Videx BASIC for DuraTrax, LaserLite, LaserLite Pro, and LaserLite Mx Data Collectors, pages 131 to 140

Pages 131 to 140 of 252

The original document is the PDF (765 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

For the Videx DuraTrax, Videx LaserLite, Videx LaserLite Mx and Videx LaserLite Pro

Page 131

LOF Function • Action Returns the length of the file in bytes. If the length of the file is greater than 32767, only the low-order word of the length is returned. • Syntax fileLen% = LOF ( filenumber% ) • Parameters Argument filenumber%

Description The number of the file used in the OPEN statement.

• Remarks See also EOF, LOFH, OPEN, and SEEK. • Returns For files opened as reference, returns the total number of records in the file. For sequential (data) files, returns the size of the file MOD 32768. The LOF function is used to check the length of a file in RAM. See the CARDCMD statement to work with files on the LaserLite Mx memory card. The following two examples each have a program line that is longer than the width of the page; so, we will use the pipe ( | ) character as an indication that the program line continues.

Chapter 4 Statement & Function Reference

123

Page 132

• Example 1 REM LOF() Function example 1 '* This example creates a new file with 70,000 bytes, '* works around the short integer limit, and prints '* file size as two integers (an integer that is a '* multiple of 32678, and an integer of the remaining '* bytes before the next multiple integer). '* It also reports the data collector's remaining memory. myFile$ = "data.txt" multipleLen% = 0 byteLen% = 0 PRINT "Building file" PRINT "Please wait"; OPEN myFile$ FOR APPEND AS #0 'this is output file FOR i% = 1 TO 700 'write 700 lines with 100 bytes to the file PRINT #0,"012345678901234567890123456789012345678901234| 56789012345678901234567890123456789012345678901234567890" NEXT i% CLOSE #0 CLS PRINT "Saved data to:" PRINT myFile$; SLEEP 0 OPEN myFile$ FOR APPEND AS #0 'this is input file multipleLen% = LOFH (0) 'this is a multiple of 32768 byteLen% = LOF (0) 'this is the number of bytes 'before the next multiple CLS PRINT "Len = ";multipleLen ; " X 32,768" PRINT "+ " ; byteLen; SLEEP 0 CLS PRINT "Memory is" PRINT ENVIRON$(1); SLEEP 0 CLOSE #0

124

Chapter 4 Statement & Function Reference

Page 133

• Example 2 REM LOF() Function example 2 '* This example illustrates the use of LOF to determine '* the number of records in a file opened for reference. '* Note: Requires the Lof2.crf to be loaded with the '* example. refFile$ = "LOF2.CRF" nl$ = CHR$(13) + CHR$(10) OPEN refFile$ FOR REFERENCE as #1 IF ERR THEN PRINT "Can't open file"; nl$; refFile$; SLEEP 0 END ENDIF recLen% = LOF (1) 'this is number of records in file PRINT refFile$;" has..."; nl$; recLen%; "total records."; SLEEP 0 CLOSE #1 END

Chapter 4 Statement & Function Reference

125

Page 134

LOF Statement • Action Sets the size of the file. • Syntax LOF ( filenumber% ) = [ intexpr2% , ] intexpr3% • Parameters Argument filenumber% intexpr2% intexpr3%

Description The file number used in the OPEN statement. Whole number multiple of 32768. Remainder over whole number multiple.

• Remarks The LOF statement is useful for clearing or truncating a file. For sequential (data) files, the LOF statement sets the size of the file. If the first argument isn’t used, it is assumed to be 0. The total size of the file is set to intexpr2% * 32768 + intexpr3%. Note: If either argument is negative, the results are undefined. The LOF statement is used to set the size of a file in RAM. See the CARDCMD statement to work with files on the LaserLite Mx memory card.

126

Chapter 4 Statement & Function Reference

Page 135

• Example REM LOF() Statement myFile$ = "data.txt" PRINT "Building file." PRINT "Please wait."; OPEN myFile$ FOR APPEND AS #0 'this is output file FOR i% = 1 TO 3000 'write 3000 lines with 10 bytes to the file PRINT #0, "012345678901234567890" NEXT i% CLOSE #0 CLS PRINT "Saved data to:" PRINT myFile$; SLEEP 0 OPEN myFile$ FOR APPEND AS #0 'this is input file byteLen% = LOF (0) 'get length of file CLS PRINT "length is " ; byteLen PRINT "purging last 1/2"; SLEEP 0 LOF (0) = byteLen%/2 'set file length to 1/2 CLS byteLen% = LOF (0) 'get length of file now PRINT "length is " ; byteLen PRINT "Clearing it."; SLEEP 0 LOF (0) = 0 'set file length to zero and clears 'contents CLOSE #0

Chapter 4 Statement & Function Reference

127

Page 136

LOFH Function • Action Returns the high-order word of the number of bytes in the numbered file. • Syntax multipleLen% = LOFH ( filenumber% ) • Parameter Argument filenumber%

Description The file number used in the OPEN statement.

• Remarks For sequential (data) files, returns the size of the file / 32768. Since an integer can only represent numbers in the range -32768 to 32767, and files can be much larger than that, the size of a file must be represented with two integers. The true size of the file is: LOFH () * 32768 + LOF () See also EOF, LOF function, OPEN, and SEEK. The LOFH function is used to check the length of a file in RAM. See the CARDCMD statement to work with files on the LaserLite Mx memory card. • Returns The size of the file as an integer. • Example See the LOF function example number 1.

128

Chapter 4 Statement & Function Reference

Page 137

LOOK$ Function • Action Returns the data from a designated field in a cross-reference file. The structure of a cross-reference file is composed of four fields: Input (key field), Field1, Field2, and Field3. (Videx BASIC) • Syntax fieldDesc$ = LOOK$ ( fieldnum% ) • Parameters Argument fieldnum%

Description The field value to be returned. If fieldnum% is 0 then the key field itself is returned.

• Remarks LOOK$ and LOOKUP are used in a program to retrieve data from a cross-reference file. LOOKUP is used first, then LOOK$. LOOKUP designates which file number to look in and what data to look for. When LOOKUP finds the data, it returns the data’s row number and sets a pointer to that row in the cross-reference file. LOOK$ is then used to designate the column of the cross-reference file that contains the data.

Chapter 4 Statement & Function Reference

129

Page 138

For example, using the cross-reference file below:

1 2

0 Input (key field) A1 A2

1 Field1 B1 B2

2 Field2 C1 C2

3 Field3 D1 D2

3

A3

B3

C3

D3

4 5

A4 A5

B4 B5

C4 C5

D4 D5

The following program line: rec% = LOOKUP (filenumber%, A3)

would search for A3 in the file, which it finds in row 3; rec% is now equal to 3. The next program line: fieldDesc$ = LOOK$ (1)

would go to column 1 of the row designated in LOOKUP and return its value; in this case, it would return B3; fieldDesc$ is now equal to B3. If the user assumes the wrong number of fields in a cross-reference file, then the results are unpredictable. Note: You can actually use cross-reference files with up to 16 fields by using Vxcrf.exe. See the DuraTrax, LaserLite, & LaserLite Pro Developer’s Reference Manual for information on using Vxcrf.exe. See also LOOKUP and OPEN. The LOOK$ function is used with cross-reference files in RAM. See the CARDCMD statement to work with cross-reference files on the LaserLite Mx memory card. • Returns If LOOKUP returns a nonzero value, then LOOK$(n) returns the nth value associated with the found key in the file. LOOK$(0) returns the key field itself. If LOOKUP returns 0, then the value of LOOK$( ) is undefined.

130

Chapter 4 Statement & Function Reference

Page 139

• Example REM LOOK$() Function and LOOKUP Function '* This example looks up data$ in the LOF2.CRF file and if '* matched, displays the data$ that was searched for, the '* record number of the matching entry, and the field being '* displayed (these 3 values are displayed on line 1). Line '* 2 displays the actual description of each field. '* NOTE: You may in turn use rec% to quickly find the '* index record for editing by using the following syntax: '* rec% = LOOKUP(1,rec%) data$ = "5E" OPEN "LOF2.CRF" FOR REFERENCE AS #1 'open cross-ref file IF ERR THEN GOSUB crf_error 'if missing, give an error ENDIF rec% = LOOKUP(1, data$) 'look for the data$ (5E) in 'the input field of file and 'store its record number IF rec% THEN 'found it BEEP 'so let them know with a beep field1$ = LOOK$(1) 'get description from field1 CLS PRINT data$;" #";rec%;" Fld 1" PRINT field1$; SLEEP 5 field2$ = LOOK$(2) 'get description from field2 CLS PRINT data$;" #";rec%;" Fld 2" PRINT field2$; SLEEP 5 field3$ = LOOK$(3) 'get description from field3 CLS PRINT data$;" #";rec%;" Fld 3" PRINT field3$; SLEEP 5 ENDIF END crf_error: BEEP CLS PRINT "Could not open" PRINT "LOF2.CRF"; SLEEP 2 RETURN

Chapter 4 Statement & Function Reference

131

Page 140

LOOKUP Function • Action Searches the specified cross-reference file for the specified key field and sets the LOOK pointer to that row in the file. (Videx BASIC) • Syntax rec% = LOOKUP ( filenumber%, (strexpr$ | intexpr% )) • Parameters Argument filenumber% strexpr$, intexpr%

Description The file number used in the OPEN statement. The data string (strexpr$) or the record number (intexpr%) to look for.

• Remarks The specified file must have been previously opened for reference, and must be properly formatted as a reference file. (A properly formatted cross-reference file is one that was created or opened with Application Builder or converted with Vxcrf.exe or Vxcrfw.exe. See the DuraTrax, LaserLite, & LaserLite Pro Developer’s Reference Manual for information on Vxcrf.exe and Vxcrfw.exe.) Each record in a reference file is randomly assigned a unique number from 1 through n (where n is the number of records in the file). This unique ID is returned from LOOKUP. If the second argument to LOOKUP is an integer instead of a string, it looks up the record with that unique ID (instead of searching for a key). See also LOOK$ and OPEN. The LOOKUP function is used to work with cross-reference files in RAM. See the CARDCMD statement to work with cross-reference files on the LaserLite Mx memory card.

132

Chapter 4 Statement & Function Reference