发生错误时如何重新运行我的程序 [Vb6]

发布于 2024-10-09 13:16:19 字数 28 浏览 0 评论 0原文

发生错误时如何重新运行我的程序[Vb6]?

How to rerun my program when an error occurs [Vb6] ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里的微风 2024-10-16 13:16:19

在 VB6 中,您可以选择通过启动表单或调用某些全局“主”例程(在项目设置中)来启动程序。选择后一个选项(全局主例程)。

在全局主例程中,将其设置为如下所示:

Public Sub MyMain()
    On Error Goto errHandler
    frmMain.Show
    Exit Sub
errHandler:
    Unload frmMain
    Resume
End Sub

Resume 将在导致错误的同一行重新启动,并且由于实际上只有一行,因此它将始终加载相同的表单。

这假设您有一个名为 frmMain 的主窗体,并且它可以成功通过 Form_Load 子例程。

In VB6 you have the option of starting a program by launching a form or by calling some global "Main" routine (in project settings). Select that latter option (global Main routine).

In your global main routine, make it something like this:

Public Sub MyMain()
    On Error Goto errHandler
    frmMain.Show
    Exit Sub
errHandler:
    Unload frmMain
    Resume
End Sub

The Resume will restart at the same line that caused the error, and since there's really only one line, it will always load the same form.

This assumes that you have a main form called frmMain and that it can get through the Form_Load subroutine successfully.

路弥 2024-10-16 13:16:19

您还可以使用 Resume Next 继续处理下一条指令

Public Sub MyMain()
    On Error Resume Next
    aNumber = someNumber / 0    'Divide by Zero will yield a run time error
    If Err<>0 Then         'In case you want to re-act with the error to the user
        MsgBox "Divide by Zero Occurred"
    End If
    On Error Goto 0    'This will un-do the effect of On Error Resume Next, meaning
                       ' that if any other error occurs, there will be a runtime error
                       ' use this if you intentionally want to
End Sub

You could also use Resume Next to continue processing the next instructions

Public Sub MyMain()
    On Error Resume Next
    aNumber = someNumber / 0    'Divide by Zero will yield a run time error
    If Err<>0 Then         'In case you want to re-act with the error to the user
        MsgBox "Divide by Zero Occurred"
    End If
    On Error Goto 0    'This will un-do the effect of On Error Resume Next, meaning
                       ' that if any other error occurs, there will be a runtime error
                       ' use this if you intentionally want to
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文