Dim i, j As Integer
Private Sub Command1_Click()
j = 0
For i = 1 To 16
MSComm1.CommPort = i
On Error Resume Next
MSComm1.PortOpen = True
If Err.Number = 0 Then
j = j + 1
Else
MSComm1.PortOpen = False
End If
Next i
Label1.Caption = "您计算机上有: " & j & "个"
End Sub