ALLEN-BRADLEY A-B VBASIC Language Development Kit (Catalog No.
Disclaimer Important User Information Solid state equipment has operational characteristics differing from those of electromechanical equipment. “Safety Guidelines for the Application, Installation and Maintenance of Solid State Controls” (Publication SGI-1.1) describes some important differences between solid state equipment and hard–wired electromechanical devices.
Table of Contents Bulletin 2708 BASIC Language Development Kit A–B Introduction to BASIC Chapter 1 What is BASIC? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is Visual BASIC ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is A-B VBASIC? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Table of Contents Bulletin 2708 BASIC Language Development Kit Special Devices in A-B VBASIC ii Chapter 4 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Device: LCD Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Device: Keypad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Device: Barcode Scanners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Table of Contents Bulletin 2708 BASIC Language Development Kit A-B VBASIC Application Library Chapter 5 A-B VBASIC and Visual BASIC Tips Appendix A Differences Between A-B VBASIC and Visual BASIC Appendix B Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Writing Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Table of Contents Bulletin 2708 BASIC Language Development Kit DECLARE {FUNCTION | SUB} name(parameters) . . . . . . . . . . . DEFINT letterrange[,letterrange]... . . . . . . . . . . . . . . . . . . . . . . . . . DEFSNG letterrange[,letterrange]... . . . . . . . . . . . . . . . . . . . . . . . . . (DEFDBL letterrange[,letterrange]...) No longer supported . . . . . . DEFLNG letterrange[,letterrange]... . . . . . . . . . . . . . . . . . . . . . . . . DEFSTR letterrange[,letterrange]... . . . . . . . . . . .
Table of Contents Bulletin 2708 BASIC Language Development Kit POS(0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PRINT [expressionlist][{,|;}] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PRINT #filenumber,[USING stringexpression;] expressionlist[{,|;}] PRINT USING formatstring; expressionlist[{,|;}] . . . . . . . . . . . . . . PUT [#]filenumber[,[recordnumber][,variable]] . . . . . . . . . . . . . . . RANDOMIZE expression . . . . . . . . .
Table of Contents Bulletin 2708 BASIC Language Development Kit In TRIG.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . In HYP.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-B VBASIC Limits C–2 C–2 Appendix D Figures 4.1 5.1 Data I/O through a Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ENVPC Main Screen (Running ENVEX1) . . . . . . . . . . . . . . . . . . . .
Chapter A–B 1 Introduction to BASIC The BASIC Language Development Kit (Catalog No. 2708-NBD) software consists of BASIC source files which you may use to decrease development time. This kit contains: • • • • • Software Diskette BASIC Language Development Kit User’s Manual (Catalog No.
Chapter 1 Introduction to BASIC What is Visual BASIC ? Almost no one is using the original ANSI standard BASIC any more. The language only allowed 26 variables, had no string capability, and was very simplistic. Visual BASIC is a product of Microsoft Corporation which expands greatly on the original language, and provides an integrated development environment containing a BASIC program editor, a BASIC compiler with a vast array of statements, and a debugging platform.
Chapter 1 Introduction to BASIC What is A-B VBASIC? A-B VBASIC is a subset of Microsoft’s Visual BASIC, consisting of those commands which are relevant in the workstation environment. A-B VBASIC includes a set of Special Devices which allows access to things like bar code scanners. Many commands which would be appropriate in a PC environment, but are not applicable on a workstation, such as color, graphics, and disk commands have been left out.
Chapter A–B 2 Developing and Running an A-B VBASIC Program The A-B VBASIC Development Procedure Step #1 – Planning The 2708-DH5Axx workstations have approximately 96K bytes dedicated for program memory. Programs that are larger than about 20-30 pages of BASIC source code need to be broken up into several smaller CHAINed programs. It is much easier to plan for this in the design stage than to be forced into it in the coding stage.
Chapter 2 Developing and Running an A-B VBASIC Program The A-B VBASIC Development Procedure (cont’d) In order to emulate programs on a PC the A-B Application Library was developed (see Chapter 5). Many basic I/O routines for the various devices found on a workstation are available through this library. These include inputs from barcode scanners, timeouts, formatted and edited keypad read routines, data conversion routine, etc.
Chapter 2 Developing and Running an A-B VBASIC Program Loading and Auto-Starting an A-B VBASIC Program The .LXE “download” file produced the the A-B VBASIC cross-compiler must be transmitted, through the Master Workstation, to the target workstation. This transmission must honor whatever protocol has been chosen for Host-Master communication in the Setup menus on the workstation: XON/XOFF, Polled Mode, Request Response, or whatever other method is enabled.
Chapter 2 Developing and Running an A-B VBASIC Program Loading and Auto-Starting an A-B VBASIC Program (cont’d) Prefix digits 9 and 10 of the network record: are 01. (Refer to Attended Workstation User’s Manual, Chapter 8 on responses to Network Directives.) Manual Intervention in an A-B VBASIC program: In a normal production use of a workstation, the application program remains running continuously. Consequently, only limited facilities are supported for manual intervention.
Chapter 2 Developing and Running an A-B VBASIC Program A-B VBASIC Run-Time Errors All errors encountered by the A-B VBASIC pseudo-code interpreter are serious enough to result in the termination of the application program. Program termination results in the following: 1. A return to the display of workstation status information (10 operator-selectable status displays discussed in the Attended Workstation User’s Manual. 2.
Chapter 2 Developing and Running an A-B VBASIC Program Power Failure Circuitry within a workstation is capable of detecting and reporting to the processor an imminent loss of power. When this occurs, all tasks are brought to a logical conclusion and the following message: POWERFAIL SHUTDOWN! is sent to the LCD. Normally, this message will never be seen because a true power failure will blank the display.
Chapter A–B 3 The A-B VBASIC CROSS-COMPILER (LXB) Overview The Visual BASIC Development Environment alone will not generate a program for a workstation. Visual BASIC allows the developer to create a program which can execute on a PC, but it is unable to create programs that a 2708-DH5 workstation can understand. To do that, we have developed a cross compiler that accepts an ASCII text file containing valid BASIC statements and creates a file that will execute only on a 2708-DH5 workstation.
Chapter 3 The A-B VBASIC CROSS-COMPILER (LXB) Invoking the Compiler The LXB compiler is executed on a PC by entering the following command. You must be in the right directory, or have the directory containing the LXB.EXE file set in your PATH. Optional parameters are in parentheses: LXB param 1 (,param2) (,param3) (,param4) The parameters are: param1 param2 param3 param4 Source filename (Default extension: .BAS) Download filename (Default extension: .LXE) Listing filename (Default extension: .
Chapter 3 The A-B VBASIC CROSS-COMPILER (LXB) Invoking the Compiler (cont’d) Examples: LXB In the case above, the operator is prompted for 3 file names. LXB Prog1 In this case, the file Prog1.BAS is read, and Prog1.LXE is the product. (This is the fastest compile option.) LXB Prog1,Prog1,Prog1 File Prog1.BAS is the source, Prog1.LXE and Prog1.LST are generated. LXB Prog1,Download,PRN Generate Download.LXE, and send listing directly to the printer (PRN). LXB Prog1,Startnow,Prog1,Wait Generate Startnow.
Chapter 3 The A-B VBASIC CROSS-COMPILER (LXB) Invoking the Compiler (cont’d) B – Downloaded Executable File The usual extension of a file that is produced by most other compilers is “.OBJ”. Those files usually go through a separate LINK step before an executable “.EXE” file is generated. However, the extension of the A-B VBASIC cross compiler output is “.LXE”. The extension “.LXE” is used for two reasons: 1. The file cannot be link edited like a usual PC object file. 2.
Chapter A–B 4 Special Devices in A-B VBASIC Introduction Most I/O in A-B VBASIC is performed by accessing special device names which are unique to the workstation. In A-B VBASIC, as in Visual BASIC, devices are accessed with the same statements as files. For example, access to the workstation’s barcode reader is obtained by an OPEN of the device named “BAR”, followed by GETs or LINE INPUTs. We highly recommend use of the VBASIC Language Development Kit (Catalog No.
Chapter 4 Special Devices in A-B VBASIC Introduction (cont’d) Some statements and intrinsic functions implicitly refer to a specific device. These are: Front panel LCD . . . . . CLS, CSRLIN, LOCATE, POS, PRINT and WRITE (without file numbers) Keypad . . . . . . . . . . . . INKEY$, INPUT$ (without filenumber), LINE INPUT (without filenumber) Beeper . . . . . . . . . . . . . BEEP, SOUND Timer . . . . . . . . . . . . . DATE$, SLEEP, TIME$, TIMER Files . . . . . . . . . . . . . .
Chapter 4 Special Devices in A-B VBASIC Device: LCD Display (cont’d) Note: See the description of PRINT USING and WRITE for details on other formatting options supported. See also the READ.BAS collection of BASIC Language Development Kit subroutines for useful LCD output subroutines, including automatic formatting of display lines, automatic clearing of the display, and cursor positioning. CLS Name$ = “Fred” PRINT “Please Enter Now!” PRINT “Thank You”; Name$; ‘ Keep cursor on second line.
Chapter 4 Special Devices in A-B VBASIC Device: Barcode Scanners Reserved device name: Open Modes: Statements: Functions: BAR INPUT LINE INPUT EOF returns TRUE when a complete record has arrived. Once TRUE, a LINE INPUT statement can be used and will immediately return the data when LINE INPUT completes. EOF returns to FALSE. LOF remains 0 until a barcode is read. Then it contains the length of the data record. It must be called before LINE INPUT.
Chapter 4 Special Devices in A-B VBASIC Device: Barcode Scanners (cont’d) This means that: 1. EOF and LOF may be called any number of times before LINE INPUT, and they will return the information for the current barcode. Program structure might make it convenient for one procedure to detect the presence of a barcode with EOF, and another to get its length with LOF, and yet another to place its contents into a string with LINE INPUT. 2.
Chapter 4 Special Devices in A-B VBASIC Device: Host Computer Reserved device names: HOST, NET, and QUE It is very easy to forward the data collected by a workstation to the host computer attached to the Master Workstation. We recommend the BASIC Language Development Kit subroutines SendQue and Send. However, if you are not using these, the simplest method is to OPEN the “file” named HOST and WRITE # or PRINT # to it. Two important features are that: 1.
Chapter 4 Special Devices in A-B VBASIC Device: Host Computer (cont’d) Note: There is no queue for data FROM the host, only a single buffer. Input operations from HOST and NET access this buffer. As just mentioned, the FIFO queue is a special file. As such, it can be manipulated as a file, through the reserved file name QUE. IMPORTANT NOTE: Outputs to the QUE device will remain in the queue and will not be sent to the host until the QUE device is closed and the HOST device is opened.
Chapter 4 Special Devices in A-B VBASIC Device: Host Computer (cont’d) For example: PRINT #NETDEV, “BAD INVENTORY NUMBER” may be trapped by the host computer as a BASIC ERROR because the complete record sent to the host will look something like this: 0101000100BAD INVENTORY NUMBER If the host program is testing for zeroes in digits 9 and 10, and is then looking for “BA” to indicate a BASIC ERROR, it will become confused by this error message, and potentially abort the programs.
Chapter 4 Special Devices in A-B VBASIC Details of Specific Statements and Functions (cont’d) CLOSE “HOST” Note: When HOST is CLOSEd, the A-B VBASIC interpreter always tells the network task that no data is available from the QUE, even if data is really present. There may be records remaining in the QUE. If so, they will not be available to the network until HOST is once again made OPEN. If necessary, use the LOF function to determine when the QUE is empty, before CLOSEing HOST.
Chapter 4 Special Devices in A-B VBASIC Details of Specific Statements and Functions (cont’d) LINE INPUT # for HOST and NET GET # for HOST and NET (OPEN with RANDOM) These statements will read one record which the host computer has sent to this. If there is no record available, the program waits for its arrival. Use the EOF or LOC functions first if waiting is not acceptable.
Chapter 4 Special Devices in A-B VBASIC Details of Specific Statements and Functions (cont’d) IOCTL$ (intrinsic function) for HOST and NET This function returns a string formatted as follows: Byte 0: ‘0’ when the workstation is offline to the network. ‘1’ when the workstation is online. Bytes 1-4: is the workstation’s number (without a minus).
Chapter 4 Special Devices in A-B VBASIC Devices: Communication Ports, Primary and Auxiliary (cont’d) A – Output to a Communication Port The BASIC Language Development Kit (Catalog No. 2708-NBD) contains subroutines SendCom, ReadEvent and Test Event for accessing the COM port when the terminal is configured as a NORMAL workstation type.
Chapter 4 Special Devices in A-B VBASIC Devices: Communication Ports, Primary and Auxiliary (cont’d) C – Modem Control Lines The primary communication port is equipped with DTR and RTS. These can be set through the IOCTL statements. The character string passed must contain two bytes. There are two valid options for each byte: “0” to turn the line off “1” to turn the line on The first byte controls DTR, the second controls RTS. Thus: IOCTL #5, “01” turns off DTR and turns on RTS.
Chapter 4 Special Devices in A-B VBASIC Device: RAM Files (cont’d) For example, in a new file: PUT #X, 1, something PUT #X, 1000, something will result in space being allocated for 1000 records, not 2! Moral: Keep record numbers under control. File Memory Management Files are allocated in blocks of RAM. Every file has at least one free byte. In essence this means that a file with a length of zero is allocated one block. Each block contains 2 bytes of overhead. The remainder contains the file’s contents.
Chapter 4 Special Devices in A-B VBASIC Device: Front Panel LEDs (cont’d) The LED in the lower left corner of alphanumeric keyboards is used as a shift lock indicator by the operating system. A-B VBASIC programs should not change it. The BASIC Language Development Kit contains a subroutine SetLED which can be called to turn LEDs on and off.
Chapter 4 Special Devices in A-B VBASIC Device: The Egg Timer Reserved device name: EGG Description: The egg timer is a word of memory which, when non-zero, is decremented by one every 1/100 second. These statements, when used with the file number associated with an OPEN “EGG”, control this timing device: SEEK statement: sets the timer to an integer or long For example: OPEN “EGG” FOR INPUT AS #4 SEEK #4, 1000 sets the timer to reach 0 in ten seconds.
Chapter A–B 5 A-B VBASIC Application Library Introduction The BASIC Language Development Kit (Catalog No. 2708-NBD) consists of a set of BASIC source files which you may use to decrease your development time and enhance the quality of your A-B VBASIC applications. Note: Subroutines for the A-B VBASIC Application Library can be found in Appendix C of this manual. The core of the library is the module ENV.BAS. ENV.
Chapter 5 A-B VBASIC Application Library Using the Library Installation consists of installing the diskette in drive A: and typing: A: INSTALIB d: Where d is the destination drive. You must first set up Visual BASIC, see Microsoft manual “Learning to Use Microsoft Visual BASIC” for installation procedures (manual is provided with the software). Also, make sure that the commands VB and LXBC are available from the installed directory “ \ LIB”.
Chapter 5 A-B VBASIC Application Library Using the Library (cont’d) If you don’t want to type this in, you will find this sample program under ENVEX1.BAS. Now, assuming that the VB command (Visual BASIC) is in your directory or is set up in your DOS PATH for you to access it, you could enter the following DOS commands: TYPE ENVPC.BAS > MAIN.BAS TYPE ENVEX1.BAS > > MAIN.BAS VB/RUN MAIN.BAS The first TYPE command copies the ENVPC library source file into MAIN.BAS.
Chapter 5 A-B VBASIC Application Library Using the ENVPC Simulator Figure 5.1 ENVPC Main Screen (Running ENVEX1) Library Test Do something Timeout of 1000 has 900 left. 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1 ^ 2 3 4 5 6 7 BDGE RX : HOST RX : NET TX : QUE RX : COM RX : COM TX : AUX RX : AUX TX : Rts1=Off Dtr1=Off Dsr1=Off Rts2=Off Dtr2=Off Dsr2=Off Line=Off 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Press TAB or ALT(A...
Chapter 5 A-B VBASIC Application Library Using the ENVPC Simulator (cont’d) Since that is all that your BASIC program would input. TAB C or ALT C: TAB A or ALT A: TAB D or ALT D: TAB L or ALT L: TAB F or ALT F: TAB N or ALT N: Com port manual input. You key in a record which simulates an input record from your RS-232 or RS-422 com port. Note that Master, Submaster, and Concentrator workstations cannot use the com port since it is in use by the network. Aux port manual input.
Chapter 5 A-B VBASIC Application Library Using the ENVPC Simulator (cont’d) The lower ASCII characters from 0 to 31 and 127 are named. These are: NUL = 0 SOH = 1 STX = 2 ETX = 3 EOT = 4 ENQ = 5 ACK = 6 BEL = 7 DEL = 127 BS = 8 HT = 9 LF = 10 VT = 11 FF = 12 CR = 13 SO = 14 SI = 15 DLE = 16 DC1 = 17 XON = 18 XON = 19 XOFF = 20 NAK = 21 SYN = 22 ETB = 23 CAN = 24 EM = 25 SB = 26 ESC = 27 FS = 28 GS = 39 RS = 30 VS = 31 The function keys are named F1..F10.
Chapter 5 A-B VBASIC Application Library Using the ENVPC Simulator (cont’d) MODIFIED%: . . . . . . TIMEOUT%: . . . . . . . GLOBALMASK%: . . ReadInt% etc. GLOBALATTR%: . . . ReadInt%, etc. INSERTMODE%: . . . True when a read changes the default value YOU set to 100th seconds before a timeout for reads YOU set mask used for ReadStr%, ReadStrField%, YOU set attributes use for ReadStr%, YOU set FALSE to disable insert mode on Read...
Chapter 5 A-B VBASIC Application Library Using the ENVPC Simulator (cont’d) Display and Keyboard You may use the full range of PRINT, LOCATE, etc. functions to write to the display. Do not use the cursor size arguments to LOCATE, but you can turn the cursor on and off using the third argument. Reading from the keyboard should only be done using TestEvent% or one of the functions which use it such as ReadEvent%, ReadStr%, ReadInt%, Menu%, etc. The keys are returned as the ASCII value of the key.
Chapter 5 A-B VBASIC Application Library Using the ENVPC Simulator (cont’d) Status Display The application status display (one of the special status displays described in the Attended Workstation User’s Manual) is not accessible through any subroutines in ENV, and is not emulated in ENVPC. Use a section of code which is conditional on the value of PcMode to set the status display. Printing Reports and Forms Since PRINT # USING..
Appendix A–B A A-B VBASIC and Visual BASIC Tips Misspellings Don’t misspell names. BASIC is unforgiving of such errors since it will just create a new variable which is zero or blank. Strings in TYPEs Strings which are defined in TYPE statements are of a fixed length. These are always blank padded on the end. Variables Beginning with “FN” Do not start any variable name with FN, Fn, Fn, or fn. BASIC treats these as a reference to the archaic DEF FN.... mechanism and produces a syntax error.
Appendix A A-B VBASIC and Visual BASIC Tips The programmer assumed that this statement would clear the second line of the display and then print “This is a test”. But, this is not what actually happens! This is compiled as: CL2 : PRINT “This is a test” ; where CL2 is a local label which is effectively ignored. The rule should be NEVER have a line which looks like: < identifier > : < rest of line > unless you INTEND for to be a label.
Appendix A–B B Differences Between A-B VBASIC and Visual BASIC This document describes the differences between Allen-Bradley VBASIC and Microsoft Visual BASIC. It first lists general characteristics unique to A-B VBASIC, and then provides additional information on keywords supported by A-B VBASIC. In this discussion, all references to “VBDOS” refer to Visual Basic for DOS. Also any references to “A-B VBASIC” refers to A-B VBASIC, used for programming a DH5 terminal.
Appendix B Differences Between A-B VBASIC and Visual BASIC b. # suffix on variables c. Floating–point constants with 8 or more significant digits d. AS DOUBLE clauses e. Functions involving DOUBLE, such as CVD and MKD 9. Restriction on the exponentiation operator Exponentiation is implemented by repetitive multiplication, so small exponents are recommended. Full real exponentiation is provided in the function called “Power!” in the BASIC source file MATH.BAS.
Appendix B Differences Between A-B VBASIC and Visual BASIC LINE INPUT Request$ IF Request$ = “JUMP” THEN CHAIN “JUMP” The interpreter does not tolerate a CHAIN to a non–existent program. Make sure that you have downloaded any program which will be CHAINed to, before any other program attempts to CHAIN to it, or the program will crash with a “Bad Chain File” error message. A special set of Network Directives is required to download a program for the express purpose of a subsequent CHAIN.
Appendix B Differences Between A-B VBASIC and Visual BASIC statements produce executable code, they should be placed at the start of a program. CONST FALSE = 0, TRUE = NOT FALSE CSNG(numeric–expression) Converts a numeric expression to a single precision value. CSRLIN Returns the current line(row) of the cursor on the front panel display. See also POS(0). Row = CSRLIN LOCATE Row, 5 CVI, CVS, CVL, (CVD) (CVD is no longer supported) See VBDOS manual for specific information. TYPE...
Appendix B Differences Between A-B VBASIC and Visual BASIC DECLARE FUNCTION GetTime$() DECLARE SUB SetTime$() The generic name for declaring a procedure’s name and its parameters is “prototyping”. LXB.EXE creates a prototype for every procedure encountered whether by the DECLARE statement, the FUNCTION statement, or the SUB statement.
Appendix B Differences Between A-B VBASIC and Visual BASIC OPTION BASE is not supported, so in order to set the lower subscript use the following: DIM A(lower TO upper) if zero is not preferred as the lowest subscript. A declaration using AS precludes variables of the same name, even with type suffixes. For example, NumOfBytes! = 10 will cause an error if there was a preceding DIM NumOfBytes AS INTEGER DIM SHARED ON$, OFF$, Now AS INTEGER DO...
Appendix B Differences Between A-B VBASIC and Visual BASIC 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.
Appendix B 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.
Appendix B 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.
Appendix B 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.
Appendix B 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...
Appendix B 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.
Appendix B 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.
Appendix B 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...
Appendix B Differences Between A-B VBASIC and Visual BASIC RETURN Returns control from a sub routine. No line number or line label clauses are supported in A-B VBASIC. RIGHT$(stringexpression, n) Returns the rightmost n characters of a string. A$ = “Now is the time for all good men to come to the aid of” B$ = RIGHT$(A$, 6) ‘B$ = “aid of” RND Returns a single–precision random number between 0 and 1. No argument is allowed in the statement.
Appendix B Differences Between A-B VBASIC and Visual BASIC statements END SELECT SGN(numeric–expression) Indicates the sign of a numeric expression. See VBDOS manual for specific details. SHARED variable [AS type] [,variable [AS type]]... Gives a SUB or FUNCTION procedure access to variables declared at the module level without passing them as parameters. All arrays in the SHARED statement must have been previously DIMensioned in module level code.
Appendix B Differences Between A-B VBASIC and Visual BASIC SOUND 1400, 2 ’1400 Hz for 2 clock ticks (20 ticks per second). SPACE$(n) Returns a string of spaces of length n. X = 25 A$ = SPACE$(X) ‘A$ equals 25 spaces. STATIC variablelist Makes simple variables or arrays local to either a FUNCTION, or a SUB and preserves values between calls. See VBDOS manual for detailed information. For arrays, STATIC must precede DIM. Also any AS clauses must match.
Appendix B Differences Between A-B VBASIC and Visual BASIC SUB GetName (Name$) DO CLS LINE INPUT “Enter your name: “;Name$ PRINT Name$;“Correct? “; LINE INPUT; YN$ YN$ = UCASE$(YN$) YN$ = “Y” or YN$ = “” THEN EXIT DO LOOP END SUB SWAP vari1,vari2 Exchanges the values of two variables. See VBDOS manual for specific details. Versions 1.0/1.1 of DH5 firmware do not support swapping single or double precision variables. This will be corrected by future versions.
Appendix B Differences Between A-B VBASIC and Visual BASIC TIME$ = “15450000” ‘ Sets time to 3:45:00.00 TIMER Returns the number of seconds elapsed since midnight. As a single precision value this is accurate to 1/100th of a second. Measurements with this function can be in error if they span midnight. See also the EGG device.
Appendix B Differences Between A-B VBASIC and Visual BASIC WEND Executes a series of statements in a loop, as long as a given condition is true. A-B VBASIC does impose a nested loop limit which should not be exceeded under normal programming conditions. WHILE INKEY$ = “”: WEND ‘Loops until a key is pressed. WRITE #filenumber [,expressionlist] Writes data to a file in memory. See the chapter on Special Devices for details on specific devices.
Appendix A–B C Application Library Subroutines In ENV.BAS and ENVPC.BAS OpenLINX . . . . . . TestEvent% . . . . . . Read Event% . . . . Send . . . . . . . . . . . SendQue . . . . . . . . SetLINE . . . . . . . . SetLED . . . . . . . . . SendCom . . . . . . . Set DTR . . . . . . . . SetRTS . . . . . . . . . GetDSR% . . . . . . . PENDING% . . . . . MEMFULL% . . . . ONLINE% . . . . . . GetDATE$ . . . . . . GetTIME$ . . . . . .
Appendix C Application Library Subroutines In TRIG.BAS FullArcTangent! . . ArcTangent! . . . . . ArcSine! . . . . . . . . ArcCosine! . . . . . . Tangent! . . . . . . . . Sine! . . . . . . . . . . . Cosine! . . . . . . . . .
Appendix C Application Library Subroutines The most important events are: TimeoutEvent . . . . NetEvent . . . . . . . . ComEvent . . . . . . . AuxEvent . . . . . . . The input timer has expired Read from network has occurred Read from the main comm port Read from the aux comm port When ComEvent or AuxEvent has occurred, InCom$ contains the LINE INPUT format line which was read from the comm line. When NetEvent has occurred, InNet$ contains the record from the host.
Appendix C Application Library Subroutines SetDTR Sets the state of Data Terminal Ready. SetRTS Sets the state of Request To Send for a comm port. Set state = TRUE to turn DTR or RTS on. You may examine the global variables RTS1%, DTR1%, RTS2%, and DTR2% to get the current state. n% is 1 for COM and 2 for AUX. SetDTR n%, state% SetRTS n%, state% SUB SetDTR ( n%, s% ) SUB SetRTS ( n%, s% ) GetDSR% Gets Data Ready status for a comm port. A TRUE is returned if DSR is ON. n% is 1 for COM and 2 for AUX.
Appendix C Application Library Subroutines PENDING% TRUE if Send will result in a pause. This should be checked before any Send, to prevent pauses in execution. WHILE PENDING% ... WEND Send Sends a record directly to the host. A string is sent to the host from this terminal. You should test ONLINE% and PENDING% if you don’t want this to pause. Send SendQue s$ Sends a record indirectly to the host through the que. A string is placed into the network queue.
Appendix C Application Library Subroutines Note: In EnvPC, dashes are returned, not slashes (MM-DD-YYYY). CL1 Clears the top line of the display and homes cursor. CL2 Clears line 2 and left justifies cursor. SUB CL1 SUB CL2 PC1 Prints a string centered on line 1. PC2 Prints a string centered on line 2. PC1 s$ SUB PC1 ( s$ ) SUB PC2 ( s$ ) ReadFlush Flushes the keyboard buffer. This clears the keyboard buffer of any pending keystrokes.
Appendix C Application Library Subroutines The global MODIFIED% is TRUE when the string was changed in any way. The strlength is the maximum number of characters to allow in the string (not including the terminal null). This must be at least fieldlength% characters long. The return value “e” is an event code. This is 0 on a normal return (operator pressed CR). The devices which are active are defined by the global variable GLOBALMASK% which is in the same format as the mask% used by % and TestEvent%.
Appendix C Application Library Subroutines ReadPassword% Inputs a password from the keyboard. e = ReadPassword% ( length%, string$ ) ; FUNCTION ReadPassword% ( n%, s$ ) ReadInt% Input an integer value from the keyboard. To suppress display of the default value, use a negative length. e = ReadInt% ( length%, int% ) FUNCTION ReadInt% ( n%, v% ) ReadLong% Input a long value from the keyboard. To suppress display of the default value, use a negative length.
Appendix C Application Library Subroutines The menu string is a string in which each menu entry is preceded by a “ | ” (vertical bar). Thus a menu$ such as: “Payment Type: | Mastercard | Visa | Amex \ “ + ” | Other | Cash“ has 5 entries; “Mastercard” is the 1st entry and may also be selected by pressing M. “Cash” is the 4th entry and may also be selected by pressing C. Note the use of “ \ ” to start a new line (the fact that the string was made by adding two strings together cannot be detected by Menu%).
Appendix C Application Library Subroutines FullArcTangent! Returns arc tangent using numerator and denominator. This is similar to ArcTangent (numerator/denominator) except it avoids the divide by 0 problems and sign problems of the normal ArcTangent function. The angle is returned in radians. Example: Usually the numerator and denominator are y and x respectively. When x is zero, y/x is undefined, but the FullArdcTangent of y,x is pi/2 or pi/2 depending on the sign of y.
Appendix C Application Library Subroutines SineH! Returns the hyperbolic sine. y! = SineH! ( x! ) FUNCTION SineH! ( x ) CosineH! Returns the hyperbolic cosine. y! = CosineH! ( x! ) FUNCTION CosineH! ( x ) ArcTangentH! Returns the inverse hyperbolic tangent. y! = ArcTangentH! ( x! ) FUNCTION ArcTangentH! ( x ) ArcSineH! Returns the inverse hyperbolic cosine for x = 0. y! = ArcSineH! ( x! ) FUNCTION ArcSineH! ( x ) ArcCosineH! Returns the inverse hyperbolic cosine for principal values.
Appendix A–B D A-B VBASIC Limits Firmware Version . . . . . . . . . . . . . . . . . Maximum PRINT USING clause . . . . . Maximum line to PRINT . . . . . . . . . . . User status display, each line . . . . . . . . Maximum barcode . . . . . . . . . . . . . . . . Maximum record to network . . . . . . . . 1.1 80 characters 200 characters 40 characters 80 characters 110 characters (system adds another 10 bytes) 200 characters 200 characters 32K, but limited by memory 10 Maximum string from INPUTS$ . . . . .
Appendix D A-B BASIC Limits When compiling programs with the LXBC command, the statistics in the LST listing file show the percent of total compiler capacity used. Maximums can be calculated from the percentages shown. How to compute memory size required for any application: Interpreter overhead . . . . . . . . . . . . . . . 6.3K Program running . . . . . . . . . . . . . . . . . . 13.7K # of CHAINed programs * 13.7K = . . . ??.? K # of host records/hour * Hours offline * bytes/rec = . . . . . . . ??.
Index A A–B VBASIC and Visual BASIC Tips, A–1 PRINT “text”, A–2 A–B VBASIC Application Library, 5–1 BASIC Language Development Kit, 5–1 Using the ENVPC Simulator, 5–4 COM and AUX, 5–8 Display and Keyboard, 5–8 Global Variables, 5–6 Network I/O, 5–8 PC Simulation Constants and Variables, 5–7 Predefined Constants, 5–5 Printing Reports and Forms, 5–9 Status Display, 5–9 VBASIC Language Development Kit Limitations, 5–7 Using the Library, 5–2 Visual BASIC, 5–2 Writing Programs, 5–3 A–B VBASIC Limits, D–1 Applic
Index M MID$, B–10 O OPEN, B–10 P PRINT, B–10 S SHARED, B–16 SOUND, B–10 Special Devices in A–B VBASIC, 4–1 #9 User Status Display, 4–15 Barcode Scanners, 4–4 Reading Barcodes, 4–4 Beeper, 4–14 Communication Ports, Primary and Auxiliary, 4–11 Input from a Communication Port, 4–12 Modem Control Lines, 4–13 Output to a Communication Port, 4–12 Details of Specific Statements and Functions, 4–8 CLOSE “HOST”, 4–9 EOF for HOST and NET, 4–10 IOCTL, 4–11 IOCTL$, 4–11 LINE INPUT # for HOST and NET GET # for HOST
ALLEN-BRADLEY A ROCKWELL INTERNATIONAL COMPANY A subsidiary of Rockwell International, one of the world’s largest technology companies, Allen-Bradley meets today’s automation challenges with over 85 years of practical plant floor experience. More than 13,000 employees throughout the world design, manufacture and apply a wide range of control and automation products and supporting services to help our customers continuously improve quality, productivity and time to market.