Debugging

The Call Stack Window

Ever pressed Ctrl+Break (enter Break Mode), with code execution stopped in a procedure and wanted to know what procedure called it? Well, the Call Stack window shows you just that:


Call Stack Window

As an example, create a new project with a command button, and enter the following code:

Public gTest As Integer
Sub Command1_click()
    Call SubRoutine1
End Sub
Sub SubRoutine1()
    Call SubRoutine2
End Sub
Sub SubRoutine2()
    ' Do something
    gTest = 1
    Stop ' Code stops here
End Sub

Run the project and press Command1. Visual Basic will enter Break Mode when it reaches the Stop statement in SubRoutine2. Now show the Call Stack window by selecting Call Stack from the View menu. You will now see three procedures listed in the box. The first item in the listbox will be SubRoutine2. At the bottom is the original event (Command1_Click()). The listbox lists all the procedures that have been called to get to the current procedure bottom up (bottom is the first procedure). So, if the listbox contained these items:

Project1.Form1.SubRoutine2 ' This procedure was called.
Project1.Form1.SubRoutine1 ' This procedure was called, and in turn called the above procedure
Project1.Form1.Command1_Click ' This event occured, which called the above procedure

The information before the Procedure name (Project1.Form1) shows what project, and what module the procedure belongs to. To go to the selected procedure, click Show.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.” - Alan Kay