The text of a manual · part 22 of 25
Attended Workstations (Catalog Nos. 2708-DH5B2L & -DH5B4L) (Series B) User Manual, pages 154 to 161
Pages 154 to 161 of 186
The original document is the PDF (513 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 Allen-Bradley 2708
Page 154
Appendix L Differences Between A-B VBASIC and Visual BASIC
Found = TRUE EXIT DO END IF LOOP CLOSE #1
EXIT {DO/FOR/FUNCTION/SUB} Exits a DO...LOOP or FOR...NEXT loop, FUNCTION, or SUB. See DO, FOR, FUNCTION, and SUB for particular statement being ended. See VBDOS manual for detailed information. See previous entry for example.
FIX(x) Returns the truncated integer part of x.
FOR counter = start TO end [STEP increment] ... NEXT [counter] Repeats a group of instructions a specified number of times. The data type of the counter controls the precision of the start, end and increment expressions. The following needs to be a LONG integer: WRONG: FOR J% = 1 to 80000: statements: NEXT J% RIGHT: FOR J& = 1 TO 80000: statements: NEXT J&
In order to count backwards (end < start), you must use the STEP clause and specify a negative value. (Historical note: I and J are commonly used because they are handy integers in FORTRAN. You can make your counter variable anything you want!)
FRE(numeric expression) FRE(stringexpression)< - NOT VALID Returns the available memory. Numeric expressions 0 through 3 are the only ones supported, and have different meanings than under VBDOS: ProgMem% = FRE(0) When the numeric expression evaluates to 0, an INTEGER is returned representing the number of bytes remaining for program pseudo–code, variable data, and the program’s pseudo stack. FileMem& = FRE(1) When the numeric expression evaluates to 1, a LONG is returned representing the number of bytes which can be used by files. (Because files are allocated in memory by blocks, rather than a byte at a time, this value will decrement by some multiple of 256.)
FREEFILE Returns the next free BASIC file number, or 0 when all file numbers are “in use”, i.e. are assigned to open files or devices. A-B VBASIC and VBDOS L–7
Page 155
Appendix L Differences Between A-B VBASIC and Visual BASIC may not return the same file numbers, even in identical programs. Just because a file number is unassigned does not imply that a new file can be created. There is a maximum number of files which can exist, open or not. See the Limits section for specifics on A-B VBASIC file and device limitations. IF NumFilesOpen < 15 THEN NextFileNum = FREEFILE
FUNCTION name[(parameterlist)][STATIC] Declares the name, the parameters, and the code that form the body of a FUNCTION. The appearance of a FUNCTION’s name on the right side of an = or in an argument list, is considered to be a call to that function, with or without an “(argument list)”. Do not use FUNCTION procedures that perform I/O in I/O statements. CurrTime$ = GetTime$ FUNCTION GetTime$() GetTime$ = TIME$ END FUNCTION
GET [#]filenumber[,[recordnumber][,variable]] Reads data from a file in memory into a variable. All 3 items after GET are required, however the record number can be consecutive commas as in, GET #1,,V$. See the chapter on Special Devices for details about input from specific devices. FIELD is not supported, use TYPE..END TYPE. TYPE EmpType Badge AS STRING * 8 Name AS STRING * 25 END TYPE DIM SHARED Emp AS EmpType OPEN “EMPLOYEE” FOR RANDOM AS #1 LEN = LEN(Emp) Rec = 0 DO WHILE NOT EOF(1) Rec = Rec + 1 GET #1, Rec, Emp IF Emp.Badge = BadgeInput$ THEN Found = TRUE: EXIT DO LOOP CLOSE #1
GOSUB {linelabel | linenumber}....RETURN Branches to and returns from a sub–routine. Linelabel on RETURNs are not supported in A-B VBASIC. BASIC’s SUB and FUNCTION procedures provide a more well–structured alternative to GOSUB...RETURN subroutines. DO CurrTime$ = LEFT$(GetTime$,4) IF CurrTime$ > OldTime$ THEN GOSUB UpdateTime OldTime$ = CurrTime$ L–8
Page 156
Appendix L Differences Between A-B VBASIC and Visual BASIC
END IF LOOP UpdateTime: LOCATE 1, 1, 0 PRINT LEFT$(CurrTime$,2); “:”; RIGHT$(CurrTime$,2); RETURN
GOTO {linelabel/linenumber} Branches unconditionally to the specified line. See VBDOS manual for detailed information.
HEX$(expression) Returns a string that represents the hexadecimal argument expression. See VBDOS manual for detailed information.
IF...THEN...ELSE Allows conditional execution, based on the evaluation of a Boolean expression. See VBDOS manual for detailed information. IF (A > B) AND (C > D) THEN Sum = (A – B) + C ELSEIF (A < B) AND (C < D) THEN Sum = (B – A) * D ELSE Sum = A * C END IF
INKEY$ Reads a character from the keyboard. If no key is currently being pressed, it returns a null string. All key codes in a DH5 terminal are a single byte. The codes corresponding to special keys can vary due to differences in keypad configurations. If necessary, use this function to get a keystroke, convert it using ASC, then print the result. A$ = “” DO WHILE A$ = “” A$ = INKEY$ LOOP
INPUT$(bytecount[,[#]filenumber]) Returns a string read from the specified file. A common error is switching the byte count and the filenumber. To prevent this, always use the # symbol with the filenumber even though it’s optional. See the chapter on Special Devices for details on INPUT$ from particular devices. J$ = INPUT$(LOC(1),#1) L–9
Page 157
Appendix L Differences Between A-B VBASIC and Visual BASIC
INSTR([start,]stringexpression1,stringexpression2) Returns the character position of the first occurrence of a string in another string. See VBDOS manual for detailed information. i = INSTR(DataIn$, CHR$(13)) ‘Look for a carriage return IF i > 0 THEN Rec$ = LEFT$(DataIn$, i–1)
INT(numeric–expression) Returns the largest integer less than or equal to numeric–expression. See VBDOS manual for detailed information.
IOCTL$([#]filenumber) Remarks in the VBDOS manual limiting IOCTL use to device drivers are not applicable to A-B VBASIC. See the A-B VBASIC Program Development Guide for details on IOCTL usage in special devices. OPEN “BAR” FOR INPUT AS #1 DO CLS PRINT “SWIPE BADGE” DO WHILE NOT EOF(1): LOOP ‘Wait for data... SOUND 1400,2 DataInfo$ = IOCTL$(1) ‘Get data on barcode input Delimiter = INSTR(DataInfo$, “/”) DataType$ = LEFT$(DataInfo$, Delimiter – 1)‘What barcode symbology? DataSrce$ = MID$(DataInfo$, Delimiter + 1)‘Slot, Wand, Laser? IF DataType$ = “C39” AND DataSrce$ = “SLOT” THEN EXIT DO LOOP
IOCTL[#]filenumber,string See IOCTL$ statement. See the chapter on Special Devices for details about specific devices. OPEN “HOST” FOR OUTPUT AS #1 IOCTL #1, “33” ‘Change last 2 digits of record prefix sent to HOST to 33.
KILL “filespec” Deletes file “filespec” from memory and releases that memory space for use by future files. KILL “!” deletes all files (except the QUE) in the DH5 terminal. See also the limits page in the A-B VBASIC manual. “*.*” wildcards are not used to avoid problems with deleting files on the PC. All remarks in VBDOS manual are applicable to A-B VBASIC, except those relating to directories. Like VBDOS, KILL is only valid on a CLOSEd file. However A-B VBASIC will not issue an error message if this is attempted, and the consequences can be dire! The QUE can be forcibly emptied by issuing a KILL “QUE” statement explicitly. L–10
Page 158
Appendix L Differences Between A-B VBASIC and Visual BASIC
LBOUND(array[,dimension]) Returns the lower bound (smallest available subscript) for the indicated dimension of an array. The default lower bound is zero. Arrays dimensioned using the TO clause in the DIM statement may have any integer value as a lowerbound. Compliment of UBOUND.
LCASE$(stringexpression) Returns a string expression with all letters in lowercase. A$ = LCASE$(“NOW IS THE TIME...”) ‘Returns, “now is the time...”
LEFT$(stringexpression, n) Returns a string consisting of the leftmost n characters of a string. See also MID$, and RIGHT$. See VBDOS manual for detailed information. CurrTime$ = LEFT$(TIME$,4) ‘Returns time in format HH:MM
LEN(stringexpression) LEN(variable) Returns the number of characters in a string or the number of bytes required by a variable. See VBDOS manual for detailed information. n = LEN(s$)
LINE INPUT[;][“promptstring”;]stringvariable Inputs an entire line (up to 255 characters) to a string variable, without the use of delimiters. The only editing character that is supported for LINE INPUT is a backspace. The DH5 development files READ.BAS and MENU.BAS provide greatly enhanced input capabilities. LINE INPUT “Enter name: “;Name$
LINE INPUT #filenumber,stringvariable Reads an entire line from a sequential file to a string variable. See the chapter on Special Devices for details about specific devices. See example listed for EOF(). OPEN “DATA.DAT” FOR INPUT AS #1 LINE INPUT #1, Title$
LOC(filenumber) Returns the current position within a file. The REMARKS paragraph in the VBDOS manual applies only to some A-B VBASIC devices. See the chapter on Special Devices for details about specific devices. L–11
Page 159
Appendix L Differences Between A-B VBASIC and Visual BASIC
OPEN “COM” FOR INPUT AS #1 ‘Must be a normal terminal. DO DO WHILE LOC(1) = 0: LOOP ‘Wait for any data in the buffer R$ = INPUT$(1, #1) Rx$ = Rx$ + R$ i = INSTR(Rx$, CHR$(13)) ‘Look for a carriage return. IF i > 0 THEN Datain$ = LEFT$(Rx$, i – 1) ‘Read in data CLS PRINT Datain$; ‘Display it Rx$ = “”: R$ = “” ‘Clear the temporary buffer END IF LOOP
LOCATE[row][,[column][,[cursor]]] Moves the cursor to the specified position. The start and stop arguments do not apply to A-B VBASIC. LOCATE 2, 1 ‘Position cursor on line 2 PRINT “Hello world”; ‘Use of semicolon prevent scrolling LOCATE 1, 1, 0 ‘Position cursor on line 1 PRINT “Goodbye world”;
LOF(filenumber) Returns the length of the named file in bytes. The REMARKS paragraph in the VBDOS manual applies only to some A-B VBASIC devices. See the chapter on Special Devices for details about specific devices. OPEN “POWER” FOR INPUT AS #1 IF LOF(1) > 0 THEN ‘If file contains data, Powerfail = TRUE then there must have been a power failure ENDIF
LTRIM$(stringexpression) Returns a copy of a string with the leading spaces removed. A = 100 A$ = LTRIM$(STR$(A)) ‘Removes leading space in front of 100.
MID$(stringexpression, start[, length]) Returns a substring of a string. See VBDOS manual for detailed information. See also MID$ statement, (replaces a portion of a string variable with another string.) A$ = “Now is the time for...” B$ = MID$(A$, 8, 3) ‘B$ now equals “the”.
MKD$, MKI$, MKL$, MKS$ (MKD$ is no longer supported) Converts numeric values to string values. See VBDOS manual for detailed information. L–12
Page 160
Appendix L Differences Between A-B VBASIC and Visual BASIC
OCT$(numeric–expression) Returns a string representing the octal value of the numeric argument. See also HEX$().
ON expression GOSUB {line–number–list/line–label–list} ON expression GOTO {line–number–list/line–label–list} Branches to one of several specified lines, depending on the value of an expression. See VBDOS manual for detailed information. N=3 ON N GOSUB GetTime, GetDate, GetLost
‘Will gosub GetLost.
OPEN file [FOR mode1][ACCESS] AS[#]filenum [LEN=reclen] Enables I/O to a file or device. All VBDOS manual references to databases and ISAM are unsupported in A-B VBASIC. The LOCK clause is not supported. See the chapter on Special Devices for details on OPENing specific devices. TYPE EmpType Badge AS STRING * 8 Name AS STRING * 25 END TYPE DIM SHARED Emp AS EmpType OPEN “EMPLOYEE” FOR RANDOM AS #1 LEN = LEN(Emp)
POS(0) Returns the current horizontal position of the cursor on the LCD display. A single argument is required but is ignored at run–time. Col = POS(0) LOCATE 1, Col
PRINT [expressionlist][{,|;}] Outputs data to the LCD display. The format for some values may vary between VBDOS and A-B VBASIC. A-B VBASIC divides the line into print zones of 8 spaces each. A semicolon at the end of the print statement keeps the cursor from advancing to the next line. PRINT “Enter your name: “; LINE INPUT; Name$
PRINT #filenumber,[USING stringexpression;] expressionlist[{,|;}] Writes data to a file in memory. A print field width is 8 characters for the LCD, 14 for others. See the chapter on Special Devices for details on specific devices. L–13
Page 161
Appendix L Differences Between A-B VBASIC and Visual BASIC
OPEN “EMPLOYEE” FOR APPEND AS #1 Format$ = “$####.##” A = 123.459 PRINT #1, USING Format$; A ‘Prints A to file #1 as $123.45
PRINT USING formatstring; expressionlist[{,|;}] Prints strings or numbers using specified format. A field width is 8 characters for the LCD. INTEGERs and LONGs will output with .00 even if .## is used. If a number is negative, a minus sign(–) will always precede it. The following formatstring characters are not supported... **, $$, **$, “,”. See the limits page in the A-B VBASIC manual for the maximum USING clause and the maximum output of a single PRINT. Format$ = “$####.##” A = 123.459 PRINT USING Format$; A
‘Prints A as $123.45
PUT [#]filenumber[,[recordnumber][,variable]] Writes from a variable or a buffer to a random or binary file. The required syntax is shown above. Omitting the recordnumber such as PUT #1, ,variable is supported, but omitting both the record number and the variable is not supported. See the chapter on Special Devices for details on specific devices. Next page for example... TYPE EmpType Badge AS STRING * 8 Name AS STRING * 25 END TYPE DIM SHARED Emp AS EmpType OPEN “EMPLOYEE” FOR RANDOM AS #1 LEN = LEN(Emp) Rec = Rec + 1 Emp.Badge = “1234” Emp.Name = “Johnathan Q. Doe” PUT #1, Rec, Emp CLOSE #1
RANDOMIZE expression Initializes (re–seeds) the random number generator. The expression is required and must be numeric. The TIMER function is commonly used to generate a pseudo–random seed as in the example below: RANDOMIZE TIMER
‘Re–seeds random number generator.
REM remark ‘ remark Allows explanatory remarks to be inserted in a program. Both forms of syntax are supported. L–14