The text of a manual · part 18 of 26
Videx BASIC for DuraTrax, LaserLite, LaserLite Pro, and LaserLite Mx Data Collectors, pages 171 to 180
Pages 171 to 180 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 171
• Example REM SEEK() Function DIM data$ * 10 myFile$ = "data.txt" OPEN myFile$ FOR APPEND AS #0 'this is output file FOR i% = 1 TO 30 'write 30 lines to the file PRINT #0, "LINE "; STR$(i%); " VIDEX LASERLITE PRO" NEXT i% CLOSE #0 PRINT "Saved data to:" PRINT myFile$; SLEEP 0 CLS dataLine$ = "" OPEN myFile$ FOR APPEND AS #0 'this is input file SEEK #0,0 'go to the beginning of file DO WHILE NOT EOF(0) 'when EOF is reached, loop stops data$ = INPUT$(50,0) 'input 50 bytes and stuff into 'the 10 byte data$ variable CLS PRINT data$ 'print the data$ variable cfp% = SEEK(0) 'return current file position PRINT "Position = ";cfp%; 'print it SLEEP 1 'pause display for 1 second or keypress LOOP CLS PRINT "END OF FILE" SLEEP 2 'pause display up to 2 seconds
Chapter 4 Statement & Function Reference
163
Page 172
SEEK Statement • Action Sets the position in a sequential (data) file for the next read or write. • Syntax SEEK [ # ] filenumber%, position% [ , ( S | E | P ) ] • Parameters Argument filenumber% position% S|E|P
Description The file number used in the OPEN statement. An offset from the start, end, or current file position. S = from start; E = from end; P = from current position.
• Remarks Set the position in a sequential (data) file for the next read or write. The file position can be specified as an offset from the start of the file, the end of the file, or the current file position. Note that the file position can be set to an arbitrarily large number by calling SEEK repeatedly with an offset from the current position. Also note that SEEK #0, 0 sets the file position at the first byte in the file, as opposed to other implementations of BASIC, where SEEK #0, 1 does the same thing. See also EOF, OPEN, SEEK, and SEEKH. The SEEK statement is used to work with a file in RAM. See the CARDCMD statement to work with files on the LaserLite Mx memory card. • Example SEEK #0, 0 SEEK #0, 0, S SEEK #0, 0, E
'set file position at first byte in file 'set file position at first byte in file 'set file position at first byte after file '(prepare to append) SEEK #0, 10, P 'advance the file position 10 bytes SEEK #0, -10, P 'move the file position back 10 bytes
See the EOF and SEEK function examples. 164
Chapter 4 Statement & Function Reference
Page 173
SEEKH Function • Action Returns the high-order word of the current file position. • Syntax cHp% = SEEKH ( filenumber% ) • Parameters Argument filenumber%
Description The file number used in the OPEN statement.
• Remarks 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 file position is: SEEKH() * 32768 + SEEK() See also SEEK. The SEEKH function is used to work with a file in RAM. See the CARDCMD statement to work with files on the LaserLite Mx memory card. • Returns For sequential (data) files, returns the current file position (from the beginning of the file) / 32768.
Chapter 4 Statement & Function Reference
165
Page 174
• Example REM SEEKH() Function '* Also uses the SEEK() function. DIM data$ * 10 myFile$ = "data.txt" PRINT "Please wait..." PRINT "making BIG file"; OPEN myFile$ FOR APPEND AS #0 'this is an output file FOR i% = 1 TO 1500 'write 1500 x 50 (75K) to the file PRINT #0,"12345678901234567890123456789012345678901234567890" NEXT i% CLOSE #0 CLS PRINT "Saved data to:" PRINT myFile$; SLEEP 0 CLS dataLine$ = "" OPEN myFile$ FOR APPEND AS #0 'this is an input file SEEK #0,0 'go to beginning of file DO WHILE NOT EOF(0) 'when EOF is reached, loop stops data$ = INPUT$(10000,0) 'input 50 bytes and stuff into the '10 byte data$ variable CLS PRINT "Position is..." cHp% = SEEKH(0) 'return current file position cfp% = SEEK(0) msg$ = "" IF cHp% > 0 THEN IF cHp% = 1 THEN msg$ = "32,767 + " ELSE msg$ = "32,767*" + STR$(cHp%) + " + " ENDIF ENDIF PRINT msg$;cfp%; 'print it SLEEP 0 'pause display for 1 second or keypress LOOP CLS PRINT "END OF FILE" SLEEP 2 'pause display for up to 2 seconds
166
Chapter 4 Statement & Function Reference
Page 175
SGN Function • Action Indicates the sign of a numeric expression. • Syntax theSign% = SGN ( intexpression% ) • Parameters Argument intexpression%
Description Any integer expression.
• Remarks None • Returns 1 if integer is positive; 0 if integer is 0; -1 if integer is negative.
Chapter 4 Statement & Function Reference
167
Page 176
• Example REM SGN() Function DIM quantity(7)
'dim an array of 8 values quantity(0) = 1 quantity(1) = -2 quantity(2) = 3 quantity(3) = -4 quantity(4) = 5 quantity(5) = 6 quantity(6) = -7 quantity(7) = 8 FOR i = 0 TO 7 CLS IF SGN(quantity(i)) = 1 THEN theSign$ = "positive" ELSE theSign$ = "negative" ENDIF PRINT "The value..." PRINT quantity(i);" is "; theSign$; SLEEP 2 NEXT i
168
Chapter 4 Statement & Function Reference
Page 177
SLEEP Statement • Action Pauses program execution for a specified number of seconds. (Videx BASIC) • Syntax 1 (for DuraTrax, LaserLite, and LaserLite Pro) SLEEP seconds% • Parameters 1 Argument seconds%
Description Number of seconds the data collector stays asleep once it enters sleep mode.
• Remarks 1 If the number of seconds is 0, then the program execution is paused indefinitely. Any event will cause program execution to resume. A subsequent INPUTEVT statement does not report key events, but other events are reported. The data collector is in a low-power state while it’s sleeping. The IrDA chip is off, so serial communications are not received. The screen remains active for the duration of the SLEEP command, but it is possible to turn the screen off before going to sleep to enter the lowest possible power (see the OPTION statement). When debugging, use the SLEEP statement to pause program execution while displaying intermediate results on the screen. • Example 1 SLEEP 0 SLEEP 3
'waits for a keypress 'waits for 3 seconds or a keypress
See the PATTERN example.
Chapter 4 Statement & Function Reference
169
Page 178
• Syntax 2 (for LaserLite Mx) SLEEP param% • Parameters 2 Argument param%
Description Length of time the LaserLite Mx’s LCD is controlled by the SLEEP statement.
• Remarks 2 For the LaserLite Mx, the value of param% specifies the LCD state when the system is asleep as follows: param% = 0
LCD is off; system sleeps indefinitely.
param% < 0
LCD is off; system sleeps for the number of seconds equal to the absolute value of param%.
0 < param% < 600
LCD is on; system sleeps for param% seconds.
param% ≥ 600
LCD is on; system idles (no sleep-wake cycle) for param% milliseconds (ms).
In all cases, the system resumes operation if a key is pressed. • Example 2 SLEEP 0
'LCD is off; system waits for a keypress
SLEEP -10
'LCD is off; system sleeps for 10 seconds or 'until a keypress
SLEEP 10
'LCD is on; system sleeps for 10 seconds or 'until a keypress
SLEEP 850
'LCD is on; system idles for 850 ms or until a 'keypress
170
Chapter 4 Statement & Function Reference
Page 179
SOUND Statement • Action Generates a sound through the speaker. • Syntax SOUND frequency%, duration% • Parameters Argument frequency% duration%
Description The desired frequency in hertz (Hz) (cycles/second). The frequency must be a numeric expression returning an integer in the range 50–8000. See the table below for the frequencies of different musical notes. The duration of the tone. The duration must be a numeric expression returning an integer in the range of 1–2000 (2000 = 2 seconds).
Musical Note Frequencies G# A A# B C c# D D# E F F# G G# A A# B C c# D D#
52 55 58 62 65 69 73 76 82 87 93 98 104 110 117 123 131 139 147 156
E F F# G G# A A# B C c# D D# E F F# G G# A A# B
165 175 185 196 208 220 233 247 262 277 294 311 330 349 370 392 415 440 466 494
C c# D D# E F F# G G# A A# B C c# D D# E F F# G
523 554 587 622 659 698 740 784 831 880 932 986 1047 1109 1175 1245 1329 1387 1480 1566
G# A A# B C C# D D# E F F# G G# A A# B C
Chapter 4 Statement & Function Reference
1661 1760 1885 1976 2083 2217 2349 2489 2637 2794 2880 3136 3322 3620 3729 3951 4186
171
Page 180
• Remarks Do not use values outside the given ranges. See also BEEP. • Example REM
SOUND Statement
SOUND 1415,100 SOUND 1440,50 SOUND 1494,50 SOUND 1523,50 SOUND 1587,50 SOUND 1698,50 SOUND 1784,50 SOUND 1880,50 SOUND 2047,50 SOUND 2329,50 SOUND 2566,50
See also the FOR...NEXT example.
172
Chapter 4 Statement & Function Reference