Dim MSComm1 As MSComm
on error goto cant_open_com1
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.DTREnable = True
MSComm1.Handshaking = comRTS
MSComm1.InBufferSize = 12 + 1 ' +1 for the CR
MSComm1.RThreshold = MSComm1.InBufferSize
MSComm1.RTSEnable = True
MSComm1.InputLen = 0 ' read entire input buffer
MSComm1.InputMode = comInputModeText
MSComm1.NullDiscard = True
MSComm1.OutBufferSize = 0 ' not used, we don't write to the serial port
MSComm1.SThreshold = MSComm1.OutBufferSize
'MSComm1.ParityReplace = ?
MSComm1.PortOpen = True
Control passes to the on error handler
When you say “control passes to the error handler”, did you forget to add an
Exit Sub? In your comments, you say you added the New declaration, but you still having a problem? Well, I just ran this code and it had no trouble opening the port.