1.on error rusume next 放在程序头一行 有错误将继续执行.2.如想中断处理 on error goto adress : : adress: msbox "串口未打开请开串口" exit sub
1.on error resume next 放在程序头一行 有错误将继续执行. 2.如想中断处理 on error goto adress : : adress: msbox "串口未打开请开串口" exit sub
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
on error resume next...'语句 ...'报错语句 if err.number=8002 then ...'处理出错 endif
放在程序头一行 有错误将继续执行.2.如想中断处理
on error goto adress
:
:
adress:
msbox "串口未打开请开串口"
exit sub
放在程序头一行 有错误将继续执行. 2.如想中断处理
on error goto adress
:
:
adress:
msbox "串口未打开请开串口"
exit 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
...'报错语句
if err.number=8002 then
...'处理出错
endif