Stack Trace in VB6

2019-02-18 19:57发布

Is it possible to get the stack trace information in Visual Basic 6.0. I mean I want to find out the function name and exact line that causes the error similar to .NET stack trace. I have created an ActiveX DLL which works fine in my test environment but it throws an error in production environment(error : 91-Object variable or With block variable not set). Any help on this much appreciated.

5条回答
聊天终结者
2楼-- · 2019-02-18 20:28

You may not be able to get at that in VB6. previous question.
Get as much information from the Err object.

查看更多
手持菜刀,她持情操
3楼-- · 2019-02-18 20:36

The only option is to do it manually, with VB6's error handling.
Here is an example:
http://www.vbaccelerator.com/home/vb/code/Techniques/RunTime_Debug_Tracing/article.asp

查看更多
我想做一个坏孩纸
4楼-- · 2019-02-18 20:42

My preferred method for doing this is HuntERR ; it's under a permissive license so can be used with impunity in any project.

http://www.devx.com/vb2themax/Tip/19792

This is an excellent static library for VB6 that permits full stack traces with as much information as you care to include.

It benefits tremendously from having some automation in your IDE to insert the error handlers and line numbers.

The archive as linked has a number of extras that I am not familiar with, including what seems to be a VB6 IDE addin - I shall be adding this to my collection of VB6 kit.

This library can literally take you from going "HUH?" to having a stack trace with full line numbering, it gives VB6 an professional level of error handling when used correctly.

查看更多
▲ chillily
5楼-- · 2019-02-18 20:47

This is a good way to do it - an answer on the existing duplicate question. Use MZTools to insert the error handlers automatically


Alternatively, you can debug your built DLL in the production environment using WinDBG, a free standalone debugger from Microsoft. Compile your DLL into native code with symbols (create PDB files).

Here's a 2006 blog post by a Microsoft guy about using Windbg with VB6, and 2004 blog post by another Microsoft guy with a brief introduction to Windbg.

查看更多
成全新的幸福
6楼-- · 2019-02-18 20:51

VB6 doesn't seem to have a decent way to do that natively.

It's a bit cumbersome, but you could put together a custom solution that adds lines to a text file whenever you want it to. Put together a method somewhere that looks like this:

Public Sub LogCall(message as String)
    Open "c:\My Documents\sample.txt" For Output As #1
    Print #1, message
    Close #1
End Sub

and then manually call it from your own functions

LogCall "MyFunction: Line 42"

It doesn't solve the problem, but it might help you narrow it down.

With regards to your specific error, I would go through and check situations where you're assigning an object to a variable - I find that it's easy to forget the Set keyword and get the exact same error when I least expect it.

查看更多
登录 后发表回答