The text of a manual · part 19 of 26
Videx BASIC for DuraTrax, LaserLite, LaserLite Pro, and LaserLite Mx Data Collectors, pages 181 to 190
Pages 181 to 190 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 181
STR$ Function • Action Returns a string representation of a number. • Syntax strEquiv$ = STR$ ( numeric expression% ) • Parameters Argument numeric expression%
Description Any numeric expression.
• Remarks The VAL function complements STR$. See also VAL example. • Returns A string representation of numeric expression%. • Example REM STR$() Function LET word$ = "Videx LaserLite" PRINT word$ lenWord% = LEN(word$) length$ = STR$(lenWord%) PRINT "is "; length$; " chars."; SLEEP 0 'pause display until keypress
Output: Videx LaserLite is 15 chars.
Chapter 4 Statement & Function Reference
173
Page 182
SWAP Statement • Action Exchanges the value of two variables. • Syntax SWAP variable1$, variable2$ or SWAP variable1%, variable2% • Parameters Argument variable1, variable2
Description Can be any variable, but both variables must be of the same type.
• Remarks Either integer or string variables can be swapped. However, the two variables must be exactly the same type or an error message appears. For example, trying to swap an integer variable with a string variable will produce an error message. • Example REM SWAP Statement sndA% = 4800 sndB% = 3300 FOR i% = 1 TO 10 SOUND sndA%, 500 SWAP sndA%, sndB% NEXT i%
174
Chapter 4 Statement & Function Reference
Page 183
TIME$ Function • Action Returns the current time from the operating system. • Syntax nowTime$ = TIME$ [ ( ) ] • Parameters None • Remarks None • Returns The TIME$ function returns an eight-character string in the pattern hh:mm:ss, where hh is the hour (00–23), mm is the minutes (00–59), and ss is the seconds (00–59). A 24-hour clock is used; therefore, 8:00 PM is shown as 20:00:00.
Chapter 4 Statement & Function Reference
175
Page 184
• Example 1 REM TIME$() Function example 1 example 1 'Returns both date and time (in two formats). Dim nowDate$,nowTime$,convDate$,convTime$ CLS nowDate$ = DATE$() nowTime$ = TIME$() PRINT "Date is :" PRINT nowDate$; 'standard date SLEEP 0 GOSUB make_date CLS PRINT "Date is :" PRINT convDate$; 'TimeWand I style date SLEEP 0 CLS PRINT "Time is :" PRINT nowTime$; 'standard time SLEEP 0 GOSUB make_time: CLS PRINT "Time is :" PRINT convTime$; 'TimeWand I style time SLEEP 0 END ' make_date ' description: Convert a DuraTrax OS date "MM-DD-YYYY" ' into a TimeWand I style date "YYYYMMDD" make_date: nowDate$ = DATE$ convDate$ = RIGHT$(nowDate$, 4) convDate$ = convDate$ + LEFT$(nowDate$, 2) convDate$ = convDate$ + MID$(nowDate$, 4, 2) RETURN ' make_time ' description: Convert a DuraTrax OS time "hh:mm:ss" into ' a TimeWand I style time "hhmmss" make_time: nowTime$ = TIME$ convTime$ = convTime$ + LEFT$(nowTime$, 2) convTime$ = convTime$ + MID$(nowTime$, 4, 2) convTime$ = convTime$ + RIGHT$(nowTime$, 2) RETURN
176
Chapter 4 Statement & Function Reference
Page 185
• Example 2 REM TIME$() Function example 2 CONST NL$ = CHR$(13) + CHR$(10) T$ = TIME$ Hr = VAL(T$) IF Hr < 12 THEN AMPM$ = " AM" ELSE AMPM$ = " PM" ENDIF IF Hr > 12 THEN Hr = Hr - 12 PRINT "The time is"; NL$; STR$(Hr); RIGHT$ (T$,6); AMPM$; SLEEP 4
Chapter 4 Statement & Function Reference
177
Page 186
TOKEN$ Function • Action Returns tokens from the given data file. This function allows you to search and scroll through the data file. • Syntax field$ = TOKEN$ ( filenumber%, stringargument$, direction% ) • Parameters Argument filenumber% stringargument$ direction%
Description The file number used in the OPEN statement. Any string expression. Direction of search. If zero, searches forward; if not zero, searches backward.
• Remarks Tokens are described as any sequence of characters that do not include any of the characters in the stringargument$. See also INPUT$, OPEN, and SEEK. The TOKEN$ function is used to work with files in RAM. See the CARDCMD statement to work with files on the LaserLite Mx memory card. • Returns Returns tokens from the data file, starting at the current file position. If the last argument is non-zero, it searches backward; otherwise, it searches forward. When there are no more tokens, " " is returned. Note that the current file position is changed after the token is read, preparing to read another 178
Chapter 4 Statement & Function Reference
Page 187
token in the same direction. The file position will be at the first nontoken character that is encountered (or at the end or beginning of the file). If you want to append data to the file after calling TOKEN$, be sure to call SEEK to place the file position at the end of the file. If TOKEN$() is used in an expression, the token is read into a temporary variable with a maximum size of 128. (See the discussion of INPUT$ on page 107.) The TOKEN$ function is useful when searching through the data file for entries. By setting stringargument$ to the field delimiter, TOKEN$ returns data with the delimiters stripped out. • Example REM TOKEN$() Function 'Creates a tab delimited file in memory and parses it out. myFile$ = "data.txt" theToken1$ = CHR$(9) theToken2$ = CHR$(13) OPEN myFile$ FOR APPEND AS #0 'this is an output file FOR i% = 1 TO 10 'write 10 tab delimited lines to file PRINT #0, "LINE "; STR$(i%) , " VIDEX DURATRAX"; STR$(i%) NEXT i% CLOSE #0 PRINT "Saved data to:" PRINT myFile$; SLEEP 0 CLS OPEN myFile$ FOR APPEND AS #0 'this is an input file SEEK #0,0 DO field1$ = TOKEN$ (0,theToken1$,0) 'first field is delimited by a tab field2$ = TOKEN$ (0,theToken2$,0) 'second field is terminated by a carriage return field2$ = LTRIM$ (field2$) 'trim the tab out CLS PRINT field1$ PRINT field2$; SLEEP 4 LOOP UNTIL field2$ = ""
Chapter 4 Statement & Function Reference
179
Page 188
TOUCH Statement (for DuraTrax, LaserLite Pro, and LaserLite Mx only)
• Action Reads or writes data to or from Touch Memory buttons capable of storing data. Note: Touch Memory buttons are also known as iButtons. (Videx BASIC) (Note: This statement is not supported by the Macintosh version of the Videx BASIC compiler.) • Syntax TOUCH mode%, button_id$, start_addr%, BYTES_VAR%, STATUS_VAR%, DATA$
• Parameters Argument mode% button_id$ start_addr% BYTES_VAR%
STATUS_VAR% DATA$
Description Specifies the operation to be performed. See Remarks. String containing the ID of the button to be accessed. The format is: ff:xxxxxxxxxxxx; where f is a hexadecimal digit of the 6-byte identification number with the more significant bytes to the left. Touch Memory button address to start reading or writing. Variable that returns the actual number of bytes processed and, for some modes, to specify the number of bytes to process. Do not use a constant or array element. Variable that returns error codes, or to set or return the continuation byte for page-oriented (DDS) operations. Variable that contains information to write, or that will receive information that is read. Must be a variable for read operations.
• Remarks The TOUCH statement is used to access the data area of certain Touch Memory buttons. Use the INPUTEVT function to simply read the ID on any Touch Memory button.
180
Chapter 4 Statement & Function Reference
Page 189
The mode% parameter is generally bit-oriented, with each bit representing a specific option. The following table defines the normal bit associations. Compatible options can usually be combined by adding the values of the various bits that are turned on. Bit#
Effect when = 0
Effect when = 1
Add
0
Read
Write
1
1
Direct (no Default Data Structure)
Default Data Structure
2
2
Reserved
Reserved
4
3
ASCII string
Hexadecimal string
8
4
Reserved
Reserved
16
5
Reserved
Reserved
32
6
Reserved
Reserved
64
7
Reserved (also 8–15 reserved)
128
The format for the button ID is “ff:xxxxxxxxxx” where f is a hexadecimal digit of the Family Code and x is a hexadecimal digit of the 6-byte identification number with the most significant bytes to the left. The colon ( : ) is to be included as shown. If this parameter is an empty string, the ID of the last accessed button is used. This is usually the button that was read in response to a button event (INPUTEVT). It might also be a button previously accessed for data reading or writing, if no other button IDs were read in between. The start address is the actual memory address for direct operations or operations using the Default Data Structure (DDS). The DDS is a pageoriented packet protocol for reading and writing data to Touch Memory buttons. In the case of a DDS operation, the start address points to the length byte (or bytes) and is usually the beginning of a page. The BYTES_VAR% variable needs to be set before calling TOUCH for direct read operations. DDS reads will determine the number of bytes from the Default Data Structure and return it in BYTES_VAR%. The number of characters in a hexadecimal mode data string is twice the number of bytes. Write operations determine the number of bytes to write, from the length of the DATA$ string. After the operation, BYTES_VAR% is set to the actual number of bytes successfully read or written. In the case of DDS write operations, the byte number includes Chapter 4 Statement & Function Reference
181
Page 190
the 4 or 5 overhead bytes. A read operation counts only the number of data bytes; that is it does not include the overhead bytes. When the operation is complete, STATUS_VAR% contains a negative number if an error occurred, otherwise it is usually set to zero. See the error code table on page 184 for a description of the error codes. A slightly different rule applies when reading or writing a Default Data Structure (DDS). When reading a DDS, the low order byte of STATUS_VAR% returns the (positive) value of the continuation page byte that immediately precedes the CRC16. For writing a DDS, the continuation byte of the written page is set to the value you have stored in STATUS_VAR% before the TOUCH statement is executed. The number of bytes stored by a DDS write operation is always four bytes more than the length of the string in DATA$ (1 length byte, 1 continuation byte, and a 2 CRC bytes; except for a DDS with over 254 bytes, the length specification uses 2 bytes.) See Touch Memory information from Dallas Semiconductor for more details. The DATA$ string contains information written to or read from the button. The maximum length when using DDS mode is 510 characters in ASCII mode or 1020 characters in hexadecimal mode. Direct mode is limited only by the length of the DATA$ string and the practicalities of the one-wire transfer process with momentary touch; however, using direct mode to read information from buttons is generally discouraged, because errors are very likely. If it is necessary to use direct mode, it is recommended that you use multiple reads with the requirement that they agree. The DATA$ parameter must be a variable unless mode% is a constant and specifies a write operation. If the returned data is longer than the maximum size of the specified string, it is truncated to the length of the string. For page-oriented operations, overhead bytes are added where necessary when writing, or removed and handled separately when reading. In these cases, DATA$ contains only true data bytes. The DDS operations pass the continuation byte (the byte immediately preceding the CRC bytes) separately through STATUS_VAR%.
182
Chapter 4 Statement & Function Reference