VB 模块内定义了一个错误处理,如果连续出错3次,则终止程序,但是目前看来代码会陷入死循环,请大神指教
PrivateDeclareSubSleepLib"kernel32"(ByValdwMillisecondsAsLong)PublicFunctioncnn()AsAD...
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Function cnn() As ADODB.Connection '定义函数
Set cnn = New ADODB.Connection
On Error GoTo handle
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & App.path & "\123.mdb;"
On Error GoTo handle
handle:
Dim i as integer
For i = 0 to 3
If Err.Number <> 0 Then
Sleep (300)
Resume 0
i = i + 1
End If
If i = 3 Then :End
End if
End Function 展开
Public Function cnn() As ADODB.Connection '定义函数
Set cnn = New ADODB.Connection
On Error GoTo handle
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & App.path & "\123.mdb;"
On Error GoTo handle
handle:
Dim i as integer
For i = 0 to 3
If Err.Number <> 0 Then
Sleep (300)
Resume 0
i = i + 1
End If
If i = 3 Then :End
End if
End Function 展开
1个回答
展开全部
Private Declare Sub Sleep Lib "kernel32"烂谈 (ByVal dwMilliseconds As Long)
Public Function cnn() As ADODB.Connection '定义函数
Set cnn = New ADODB.Connection
On Error GoTo handle
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & App.Path & "\123.mdb;"
Exit Sub '与错误处理例程断开,避免在正常执行中执行到下面代码
handle:
蚂此dim i As Integer
If Err.Number <> 0 Then
闷历迅 If i >= 3 Then End '这句要放在resume前面,这样出错3次后退出程序,下面的就执行不到了
Sleep (300)
i = i + 1 '计数也要放在resume前面,否则resume跳到了原处,就无法计数了
Resume 0
End If
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询