tags:

views:

47

answers:

1
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

+1  A: 

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.

Private Sub Form_Load()

  Dim MSComm1 As New 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
  MSComm1.RThreshold = MSComm1.InBufferSize
  MSComm1.RTSEnable = True
  MSComm1.InputLen = 0
  MSComm1.InputMode = comInputModeText
  MSComm1.NullDiscard = True
  MSComm1.OutBufferSize = 0
  MSComm1.SThreshold = MSComm1.OutBufferSize

  MSComm1.PortOpen = True

  Exit Sub

cant_open_com1:
    Debug.Print Err.Description

End Sub
raven
Note, vb6 won't permit Dim MSComm1 As New MSComm. It has to be two statements: Dim MSComm1 Set MSComm1 = New MSComm and you *must* include the "Set"
Mawg
@mawg: As I said, *I just ran this code and it had no trouble opening the port*. Did you? If you did, and it doesn't work for you, well then I guess we have another issue to contend with. Perhaps you should post a question inquiring as to why it doesn't work?
raven