自动生成问题处理 [英] Automatically generating handling of issues

查看:128
本文介绍了自动生成问题处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更多的是观察,而不是真正的问题:MS-Access(通常是VBA)非常缺少一种工具,该工具可以自动生成错误处理代码,并且在发生错误时可以显示行号。您找到解决方案了吗?它是什么?自几年前找到正确的基本问题答案以来,我才意识到自己节省了数百小时,我想看看您对这个非常重要的问题有什么想法和解决方案。

This is more an observation than a real question: MS-Access (and VBA in general) is desperately missing a tool where error handling code can be generated automatically, and where the line number can be displayed when an error occurs. Did you find a solution? What is it? I just realized how many hundreds of hours I spared since I found the right answer to this basic problem a few years ago, and I'd like to see what are your ideas and solutions on this very important issue.

推荐答案

我的解决方案如下:


  1. 安装 MZ工具,这是VBA的一个非常有趣的插件。不,他们没有付钱给我写这个。版本3是免费的,但自版本8.0起,该插件已在市场上出售。

  2. 编写标准错误处理程序代码,例如该代码(请参见MZ-Tools菜单/选项/错误处理程序)。 ):

  1. install MZ-Tools, a very interesting add-on for VBA. No they did not pay me to write this. Version 3 was free, but since version 8.0, the add-in is commercially sold.
  2. program a standard error handler code such as this one (see MZ-Tools menu/Options/Error handler):







On Error GoTo {PROCEDURE_NAME}_Error
{PROCEDURE_BODY}
On Error GoTo 0
Exit {PROCEDURE_TYPE}

{PROCEDURE_NAME}_Error:
debug.print "#" & Err.Number, Err.description, "l#" & erl, "{PROCEDURE_NAME}", "{MODULE_NAME}"






然后,通过单击MZ-Tools菜单中的相应按钮,可以将该标准错误代码自动添加到您的所有proc和功能中。您会注意到,这里我们指的是VBA标准库 Erl中的一个隐藏且未记录的功能,它代表错误线。你说对了!如果您要求MZ-Tools自动为您的代码行编号,那么 Erl将为您提供发生错误的行号。您将在立即窗口中获得错误的完整描述,例如:


This standard error code can be then automatically added to all of your procs and function by clicking on the corresponding button in the MZ-Tools menu. You'll notice that we refer here to a hidden and undocumented function in the VBA standard library, 'Erl', which stands for 'error line'. You got it! If you ask MZ-Tools to automatically number your lines of code, 'Erl' will then give you the number of the line where the error occured. You will have a complete description of the error in your immediate window, such as:

#91, Object variable or With block variable not set, l# 30, addNewField, Utilities

当然,一旦您意识到系统的重要性,您可以想到一个更复杂的错误处理程序,它不仅会在调试窗口中显示数据,而且还会:

Of course, once you realize the interest of the system, you can think of a more sophisticated error handler, that will not only display the data in the debug window but will also:


  1. 显示它作为屏幕上的消息

  2. 在错误日志文件中自动插入一行,其中包含错误
  3. 的描述
  4. 如果使用Access或连接到数据库,则将记录自动添加到Tbl_Error表中!

意味着在用户级别生成的每个错误都可以存储在文件或表中,也可以存储在计算机或网络中的某个位置。我们是在谈论构建与VBA一起使用的自动错误报告系统吗?

meaning that each error generated at the user level can be stored either in a file or a table, somewhere on the machine or the network. Are we talking about building an automated error reporting system working with VBA?

这篇关于自动生成问题处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆