title: visual basic 6.0 comm port code error
body: <p>I am actually trying to get data from <code>port1</code> but the error <code>Invalid port number</code> is generated.</p>
  
  <p>The code is:</p>
  
  <pre><code>Private Sub Command1_Click()
      MsgBox ("The port is open " &amp; MSComm1.PortOpen)
      If (MSComm1.PortOpen = False) Then
      MSComm1.PortOpen = True
      End If
      Command1.Enabled = False
      Command2.Enabled = True
  End Sub
  
  Private Sub Command2_Click()
      If (MSComm1.PortOpen = True) Then
      MSComm1.PortOpen = False
      End If
      Command1.Enabled = True
      Command2.Enabled = False
  End Sub
  
  Private Sub Form_Load()
      With MSComm1
      .CommPort = 1
      .RThreshold = 1
      .RTSEnable = True
      .Settings = "9600,N,8,1"
      .InputLen = 127
      .SThreshold = 1
      End With
  End Sub
  
  Private Sub Form_Unload(Cancel As Integer)
      If (MSComm1.PortOpen = True) Then
      MSComm1.PortOpen = False
      End If
  End Sub
  
  Private Sub MSComm1_OnComm()
      Dim Buffer As String
  
      Select Case MSComm1.CommEvent
      Case comEvReceive
      'Text1.Text = " "
      Buffer = MSComm1.Input
      Text1.Text = Text1.Text &amp; Buffer
      End Select
  End Sub
  </code></pre>