Liberty BASIC Help Online

ONCOMERROR
 
ONCOMERROR [branchLabel]
 
Description:
This sets or clears a branch label for handling errors when doing serial communications. 
 
    'to set a branch label for error handling
    oncomerror [myComErrorHandler]
 
    'to disable com error handling
    oncomerror
 
When an error does occur, three special variables will be set:
 
    ComError$      This holds a description of the error
    ComPortNumber  This holds the port number of the error
    ComErrorNumber     In the case of Win 95/98/ME this var is set to one of the Win16 com error codes, and in the case of Win NT/2K/XP OS error codes.
 
 
Usage:
 
    'open com2
    open "COM2:9600,n,8,1" for random as #1
 
    'enable the com error handler
    oncomerror [handleIt]
 
    'try to open com2 again, triggering handler
    open "COM2:9600,n,8,1" for random as #2
 
    'we never get this far because of the error
    print "we never get this far because of the error"
    input r$
 
[handleIt]
 
    'disable the com error handler
    oncomerror
 
    'print out the error and port
    print "Error: "; ComError$
    print "Port number: "; ComPortNumber
    print "Error code: ";ComErrorNumber
 
    'close com2
    close #1
 
    end
 
See also:  OPEN "COMn:..."


Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/