VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 18

Entering Break Mode Manually

You can manually enter Break mode in several ways:
  • Press Ctrl+Break

  • Choose Break from the Run menu

  • Click on the Break button on the toolbar

If you aren’t sure what part of your code may be responsible for a problem, but you see it when it happens, the ability to manually enter Break mode can be handy. Because it is possible for so many Windows events to occur in rapid succession, however, the few hundred milliseconds it takes for you to click your mouse or press a key after you spot the problem may put you into a part of your code that has nothing to do with the problem.

If you can localize your problem to some extent, you can also specify places in your code at which to enter Break mode automatically:

  • Set a breakpoint

  • Use the Stop command

You can toggle a breakpoint either from the Debug menu, as shown in Figure 18.7, or by pressing the F9 key. If the current line has no breakpoint set, F9 sets one; if the line already has a breakpoint, F9 turns it off. If you want to remove all breakpoints from your project, you can either use the Debug menu to do so or press Ctrl+Shift+F9. The color of the line in the VB code editor reflects the status of any line with a breakpoint.

Setting a breakpoint from the Debug menu.
FIGURE 18.7 Setting a breakpoint from the Debug menu.

Once set, your program will enter Break mode the moment that it reaches the line of code with the breakpoint. The program’s execution is suspended just before that line of code executes.

You can also toggle individual breakpoints on or off by clicking in the bar to the right of a line of code in Code window.

One problem with breakpoints is that they are not preserved between programming sessions. That is, if you close a project after setting a breakpoint and then reopen the project, your breakpoints will be gone. If you want to set a breakpoint that persists between sessions, use the Stop command. The moment the Stop line is reached in your code, the program enters Break mode.

WARNING - Avoiding Inadvertant Stop Commands: If you’re worried about inadvertently leaving a Stop command in a project before you deliver it to a client, remember that you can use a conditional compiler switch:

#Const DEBUGMODE = 1
#End If

To be extra safe, set the value of DEBUGMODE on the command line. Then you won’t have to worry about forgetting to remove the definition of the compiler constant from your code either.


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved