vba 如何检查调用堆栈

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/682932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:19:08  来源:igfitidea点击:

How to Inspect Call Stack

ms-accessvbaaccess-vbacallstack

提问by THEn

Would it be possible to see the CallStackin VBA for MS Access 2003? That is to say, would it be possible to see from what procedureor functionanother functionwas called?

是否可以CallStack在 VBA 中查看 MS Access 2003?也就是说,从什么procedurefunction另一个function被称为是可能的吗?

采纳答案by David-W-Fenton

There is no programmatic way in VBA to view the call stack that I know of. The usual solution to this problem is to use some structure to track calling of functions, but it always seems like a kludge to me, and really of use only when programming (not at runtime), in which case it seems to me that the VBE's built-in capability for seeing the call stack is sufficient.

VBA 中没有以编程方式查看我所知道的调用堆栈。这个问题的通常解决方案是使用一些结构来跟踪函数的调用,但对我来说似乎总是杂乱无章,而且只有在编程时(不是在运行时)才真正有用,在这种情况下,在我看来 VBE 的查看调用堆栈的内置功能就足够了。

And, BTW, I always put the call stack button on my VBE toolbar, since it's one of the most frequently used functions for me. I also add the compile button -- I think it's crazy that it's not on the toolbar by default because it encourages people to code without ever forcing a compile. Then again, Access 2000 didn't even use Option Explicit by default (supposedly for consistency with the other apps using the VBE -- in other words, dumb down Access in order to make it consistent with apps that aren't nearly as code-heavy).

而且,顺便说一句,我总是把调用堆栈按钮放在我的 VBE 工具栏上,因为它是我最常用的功能之一。我还添加了编译按钮——我认为默认情况下它不在工具栏上是很疯狂的,因为它鼓励人们在不强制编译的情况下进行编码。再说一次,Access 2000 在默认情况下甚至没有使用 Option Explicit(据说是为了与使用 VBE 的其他应用程序保持一致——换句话说,简化 Access 以使其与几乎不是代码的应用程序保持一致——重的)。

But I digress...

但我离题了...

回答by shahkalpesh

At runtime, View menu -> Call Stack (or press CTRL + L).

在运行时,查看菜单 -> 调用堆栈(或按 CTRL + L)。

回答by Patrick Honorez

Eventually, add an optional parameter to your function, and pass the caller name that way. For forms, you can use Me.Nameas the parameter.

最后,向您的函数添加一个可选参数,并以这种方式传递调用者名称。对于表单,您可以Me.Name用作参数。

回答by user4594176

Yes it's possible, BUT it's not quite usefull!

是的,这是可能的,但它不是很有用!

Private Declare Sub SetMode Lib "vba332.dll" Alias "EbSetMode" (ByVal lngMode As Long)
Private Declare Function GetCallStackCount Lib "vba332.dll" Alias "EbGetCallstackCount" (lngCount As Long) As Long
Private Declare Function GetCallStackFunction Lib "vba332.dll" Alias "EbGetCallstackFunction" (ByVal Lvl As Long, ByRef strBase As String, ByRef strModule As String, ByRef strFunction As String, ByRef Done As Long) As Long

Before use GetCallStackCount and GetCallStackFunction call SetMode(2), and after SetMode(1).

在使用 GetCallStackCount 和 GetCallStackFunction 之前调用 SetMode(2),在 SetMode(1) 之后。