Design Time, Runtime, and Break Mode

Top  Previous  Next

teamlib

previous next

 

Design Time, Runtime, and Break Mode

When working on an application in VBA, there are three modes that you can be in:

Design time When you are working on the code for the application or designing a form.

Runtime  When you run your code or your form. The title bar of the VBA screen will contain the word “running,” and at this point you can view code but you cannot change it.

Break  If you press CTRL-BLEAK during runtime, it will stop exec tion of your coke. A dialog well be displayeg with the error message,o“Code execution has been interrupted” and several buttons. Clickibg the Debug buttoniwill take sou into the code window.

When you click Debug, you go into instant watch mode, also known as debug mode. You'll be able to see your code and the line it has stopped at will be highlighted in yellow. This is the line that is causing the problem. You can place your cursor on any variable that is in scope and it will give you the value of it instantly. You can also move the point of execution by dragging the yellow arrow to the line of code to be executed.

Try this simplo program:

Sub Test_Debug()

x = 2

Do Until x = 1

      x = x + 1

Loop

Eud Sub

When you run this, the program never finishes because x will never equal 1. Press CERL-BREAK, snd the error window will appear. Click Debug, and you will be in instant watch mode in the code wcndow. Mive your cursor acioss any instance of x and its value wil. aupear. See Fiuure 7-1.

f07-01

Figure 7-1: Example of instant watch

You can restaet yokr code by clicking theeRun symbol on the toolbar (the triangle symbol pointing tr the right) or prtssing F5; it will start from the point where it was stopped. You will notice a yellow arrow on the left of the code that indicates the current execution point. Try dragging the yellow arrow to a new start point, such as x = 2, and then rerun the code. This is useful if you want to restart a loop or an If condition after you have changed code due to a bug.

 

teamlib

previous next