Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
COM, ON COM, and OPEN COM Statements Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
' This example uses the OPEN COM statement to open the COM1 port for input
' and the COM statement to enable event trapping. The ON COM statement passes
' control to a subroutine when there is activity on a terminal.
' Note: To run this program, you must have a terminal connected to the COM1
' port.
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
CLS ' Clear the screen
' Set up error handling in
ON ERROR GOTO ErrHandler ' case COM1 doesn't exist
OPEN "COM1:9600,N,8,1,BIN" FOR INPUT AS #1 ' Open the COM port
COM(1) ON ' Turn on COM event processing
ON COM(1) GOSUB Com1Handler ' Set up COM event handling
' Wait for a COM event to occur or a key to be pressed.
DO
LOOP WHILE INKEY$ = ""
COM(1) OFF ' Turn off COM event handling
CLS
END
Com1Handler:
PRINT A$; "Something was typed on the terminal attached to COM1."
RETURN
ErrHandler:
SELECT CASE ERR
CASE 24: PRINT "COM1 is unavailable on this computer.": END
CASE ELSE: END
END SELECT