Option Explicit Dim a As Integer Dim blnAutoSendFlag As Boolean Dim openFlag As BooleanPrivate Sub Form_Load() MSComm1.Settings = "9600,n,8,1" MSComm1.InputMode = comInputModeBinary '采用二进制传输 MSComm1.InBufferCount = 0 '清空接受缓冲区 MSComm1.OutBufferCount = 0 '清空传输缓冲区 MSComm1.RThreshold = 1 '产生MSComm事件 MSComm1.InBufferSize = 1024 Shape1.FillStyle = 0 OpenPortNum End SubPrivate Sub OpenPortNum() On Error GoTo uerror For a = 1 To 16 MSComm1.CommPort = a MSComm1.PortOpen = True If MSComm1.PortOpen = True Then Print "可用Com号= "; a MSComm1.PortOpen = False End If Next Exit Sub uerror: Print "出错或占用Com号= "; a Resume Next End Sub
Dim a As Integer
Dim blnAutoSendFlag As Boolean
Dim openFlag As BooleanPrivate Sub Form_Load()
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputMode = comInputModeBinary '采用二进制传输
MSComm1.InBufferCount = 0 '清空接受缓冲区
MSComm1.OutBufferCount = 0 '清空传输缓冲区
MSComm1.RThreshold = 1 '产生MSComm事件
MSComm1.InBufferSize = 1024
Shape1.FillStyle = 0
OpenPortNum
End SubPrivate Sub OpenPortNum()
On Error GoTo uerror
For a = 1 To 16
MSComm1.CommPort = a
MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
Print "可用Com号= "; a
MSComm1.PortOpen = False
End If
Next
Exit Sub
uerror:
Print "出错或占用Com号= "; a
Resume Next
End Sub