【发布时间】:2020-10-01 17:11:03
【问题描述】:
我是 On Error GoTo 的新手。我有一个检查客户状态的功能。如果为0,则通过,否则代码应为5-18。我正在尝试到达错误到达的位置,弹出一个带有该错误的消息框,一旦用户单击确定,我的应用程序将从头开始并运行以查看该错误是否已修复或是否存在另一个在那之后的错误。不确定 On Error GoTo 是否是最好的方法。我不知道如何根据返回的数字而不是一条通用消息来显示每条单独的消息。目前,当我运行时,我一直不得不按确定,然后我收到错误消息并按确定等。
On Error GoTo Error
Debug.Print "Starting Check."
TryAgain:
client.Read "State", State
If State <> 0 Then
ElseIf code = 5 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 6 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 7 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 8 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 9 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 10 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 11 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 12 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 13 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 14 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 15 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 16 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 17 Then
Message = "*** - ERROR: Description Here"
ElseIf code = 18 Then
Message = "*** - ERROR: Description Here"
End If
Else
MsgBox ("Successful")
Exit Function
End If
Error:
'Display Message from above is what i am having trouble with
Resume TryAgain
【问题讨论】:
-
将
Exit Function移出End If并放在Error:之前 -
另外从你的代码看来你有一个额外的
End If?