VB编写串口程序,如何检测计算机有几个COM口?

使用MSCOMM控件。
2024-11-20 12:25:34
推荐回答(1个)
回答1:

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