VB实时错误424
PrivateSubForm_Load()WithfrmPort1If.MSComm.PortOpen=TrueThen.MSComm.PortOpen=False(此处...
Private Sub Form_Load()
With frmPort1
If .MSComm.PortOpen = True Then .MSComm.PortOpen = False(此处显示错误)
For i = 1 To 16
On Error Resume Next
'当运行发生错误时,控件转到紧接着发生错误的语句之后的语句,并在此继续运行
.MSComm.CommPort = i
.MSComm.PortOpen = True
Select Case Err.Number
Case 0 '错误号为0(也就是没出错),
cboPort.AddItem "Com" & Trim(i)
.MSComm.PortOpen = False
Case 8005 '错误号为8005,也就是端口被占用
cboPort.AddItem "Com" & Trim(i) & " 已经占用"
.MSComm.PortOpen = False
End Select
Err = 0 '将错误号置0. 注:Err.Number可以简写为Err ,2者等效
Next
End With
cboPort.ListIndex = 0
cboBaud.AddItem ("9600")
cboBaud.AddItem ("115200")
cboBaud.ListIndex = 0
End Sub 展开
With frmPort1
If .MSComm.PortOpen = True Then .MSComm.PortOpen = False(此处显示错误)
For i = 1 To 16
On Error Resume Next
'当运行发生错误时,控件转到紧接着发生错误的语句之后的语句,并在此继续运行
.MSComm.CommPort = i
.MSComm.PortOpen = True
Select Case Err.Number
Case 0 '错误号为0(也就是没出错),
cboPort.AddItem "Com" & Trim(i)
.MSComm.PortOpen = False
Case 8005 '错误号为8005,也就是端口被占用
cboPort.AddItem "Com" & Trim(i) & " 已经占用"
.MSComm.PortOpen = False
End Select
Err = 0 '将错误号置0. 注:Err.Number可以简写为Err ,2者等效
Next
End With
cboPort.ListIndex = 0
cboBaud.AddItem ("9600")
cboBaud.AddItem ("115200")
cboBaud.ListIndex = 0
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询