开发者

Stack Trace in VB6

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开发者_JAVA技巧 it throws an error in production environment(error : 91-Object variable or With block variable not set). Any help on this much appreciated.


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.


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


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜