The text of a manual · part 15 of 26
Videx BASIC for DuraTrax, LaserLite, LaserLite Pro, and LaserLite Mx Data Collectors, pages 141 to 150
Pages 141 to 150 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 141
• Returns If the key is found, its ID is returned; otherwise, 0 is returned. • Example See the LOOK$ example.
Chapter 4 Statement & Function Reference
133
Page 142
LTRIM$ Function • Action Returns a copy of a string with leading spaces removed. • Syntax data$ = LTRIM$ ( stringexpression$ ) • Parameters Argument stringexpression$
Description Any string expression.
• Remarks See also RTRIM$. • Returns Copy of string with no leading spaces.
134
Chapter 4 Statement & Function Reference
Page 143
• Example REM LTRIM$() Function and RTRIM$() Function myFile$ = "data.txt" LET NL$ = CHR$(13) + CHR$(10) PRINT "Building file..." PRINT "Please wait" OPEN myFile$ FOR APPEND AS #0 rem this is output file FOR i% = 1 TO 10 rem write 10 lines to file data$ = "LINE" + STR$(i%) + "." PRINT #0, data$ NEXT i% CLOSE #0 CLS PRINT "Saved data to:" PRINT myFile$; SLEEP 0 dataLine$ = "" OPEN myFile$ FOR APPEND AS #0 rem this is input file SEEK #0,0 DO data$ = TOKEN$ (0,NL$,0) IF data$ = "" THEN EXIT DO CLS PRINT CHR$(34); data$; CHR$(34) PRINT CHR$(34); LTRIM$(RTRIM$(data$)); CHR$(34); SLEEP 1 LOOP CLOSE #0 SLEEP 0
Chapter 4 Statement & Function Reference
135
Page 144
MID$ Function • Action Returns a substring of a string. • Syntax result$ = MID$ ( stringexpression$, start% [, length% ] ) • Parameter Argument stringexpression$ start% length%
Description The string that the substring is extracted from; this can be any string expression. Designates the character position in the string expression where the substring starts. Designates the number of characters to extract.
• Remarks The start% and length% arguments must be in the range of 1–32767. If the length% argument is omitted or if there are fewer than length% characters to the right of the start% character, the MID$ function returns all characters to the right of the start% character. If start% is greater than the number of characters in the string expression, MID$ returns a null string. Use the LEN function to find the number of characters in a string expression. See also LEFT$, LEN, MID$ statement, and RIGHT$. • Returns All characters to the right of the start% character.
136
Chapter 4 Statement & Function Reference
Page 145
The following example has a program line that exceeds the width of the page; so, we will use the pipe ( | ) character to indicate that the program line continues. • Example REM MID$() Function DIM toSend$ * 500 toSend$ = "Sending this sentence to the screen and out the| serial port one character at a time." PRINT "Press when..." PRINT "ready."; SLEEP 0 FOR i% = 1 TO LEN(toSend$) theChar$ = MID$(toSend$,i%,1) CLS PRINT "Sending..."; theChar$; COMMPRINT theChar$ GOSUB slow_down NEXT i% CLS PRINT "Finished job" SLEEP 0 END slow_down: FOR r = 1 TO 200 NEXT r RETURN
'this subroutine is just a delay to 'display the data longer
Chapter 4 Statement & Function Reference
137
Page 146
MID$ Statement • Action Replaces a portion of a string variable with another string. • Syntax MID$ ( stringvariable$, start% [, length% ] ) = stringexpression$ • Parameters Argument stringvariable$ start% length% stringexpression$
Description The string variable being modified. A numeric expression giving the position in stringvariable$ where the replacement starts. The number of characters to replace. The length is a numeric expression. The string expression that replaces part of the string variable.
• Remarks If length% is not specified, then substitution continues until the end of either stringexpression$ or stringvariable$ is reached. See also LEFT$, LEN, MID$ function, and RIGHT$. • Example REM MID$() Statement LET test$ = "Paris, France" LOCATE 0,0 PRINT test$ MID$(test$,8) = "Texas " 'replace the characters in test$, LOCATE 1,0 'starting with the 8th char, with "Texas" PRINT test$; SLEEP 3 'pause display for 3 seconds or until keypress
Output: Paris, France Paris, Texas
138
Chapter 4 Statement & Function Reference
Page 147
ON…GOSUB, ON...GOTO Statement • Action Branches to one of a list of subroutines, depending on the value of an expression. • Syntax 1 ON expression$ GOSUB label { , label } • Syntax 2 ON expression$ GOTO label { , label } • Parameters Argument expression$ label
Description Determines which label the program branches to. The subroutine to branch to.
• Remarks The expression$ argument can be any numeric expression. If the value is 0, then the first subroutine is executed. If the value is 1, then the second subroutine is executed, and so on. The label arguments are a list of the subroutines separated by commas. If the value of expression$ is out of range, then the line is skipped, and the next line is executed. The following example has a program line that exceeds the width of the page; so, we will use the pipe ( | ) character to indicate that the program line continues.
Chapter 4 Statement & Function Reference
139
Page 148
• Example REM ON...GOSUB Statement '* '* Monitors events in the data collector and calls '* subroutines. '* CONST false = 0, true = Not false, NL$ = CHR$(13) + CHR$(10) DIM display$ * 34 running% = true 'set running to true display$ = "Waiting on you..." + NL$ + "P switch = exit" 'preprompt them WHILE running% 'event loop CLS PRINT display$; 'display a prompt of some kind INPUTEVT 0, 0, 0, 0, type%, symbol%, device%, data$ 'get an event ON type% GOSUB fn_null, fn_input, fn_exit, fn_null,| fn_up, fn_dn, fn_power WEND END fn_null:
'does nothing
RETURN fn_input: 'an input routine goes here CLS BEEP PRINT "Input routine" SLEEP 2 RETURN fn_exit: running% = false% RETURN
'an exit routine goes here fn_up: SOUND 2933, 125 RETURN
'a scroll up routine goes here 'notify user that we got the keypress fn_dn: SOUND 2933, 125 RETURN
'a scroll down routine goes here 'notify user that we got the keypress fn_power: OPTION( 256) = 0 SLEEP 0 OPTION( 256) = 1 RETURN
140
'turn off the LCD 'sleep indefinitely 'turn the LCD back on
Chapter 4 Statement & Function Reference
Page 149
OPEN Statement • Action Opens named file. • Syntax OPEN file$ FOR ( APPEND | REFERENCE ) AS [ # ] filenumber% • Parameters Argument file$ filenumber%
Description A string expression that specifies a filename. An integer expression between 0 and 31. When a OPEN is executed, this number is associated with the file as long as it is open. Other I/O statements may use the number to refer to the file.
• Remarks If the file is opened for APPEND, text data can be printed to the file. On the DuraTrax, LaserLite, LaserLite Pro, and LaserLite Mx it is only possible to open a single file in RAM for append (this is the data file). The name most recently used to open the data file is the name by which it is saved when it is transferred to the computer. If the file is opened for REFERENCE, the file is assumed to be properly formatted as a cross-reference file. (A properly formatted crossreference 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.) LOOKUP can be called for files opened for REFERENCE. The file number must be between 0 and 31. File numbers greater than 31 result in an error. It is recommended that the ERR function be called after the OPEN statement or other file handling routines. Chapter 4 Statement & Function Reference
141
Page 150
See also CLOSE, EOF, LOF, LOFH, LOOKUP, and SEEK. The OPEN statement is used to open a file in RAM. See the CARDCMD statement to open files on the LaserLite Mx memory card. • Example See the LOF function examples 1 and 2.
OPTION Function • Action Returns the status of an environment option . (Videx BASIC) • Syntax result% = OPTION ( optionnumber% ) • Parameters Argument optionnumber%
Description The option number.
• Remarks Returns the value of options less than 255. The value of options less than 128 are returned as true (-1) or false (0). See also OPTION statement. • Returns The status of the environment option.
142
Chapter 4 Statement & Function Reference