Datasheet
Sometimes when you perform a series of programming tasks many times, there are better ways to
approach the problem than writing a macro. For example, you may be able to make your program repeat
the steps inside a loop. Or you may be able to extract the common code into a subroutine and then call it
repeatedly rather than repeating the code many times. In these cases, your application doesn’t need to
contain a long sequence of repetitive code that may be hard to debug and maintain.
Macros are generally most useful when you must write similar pieces of code that cannot be easily
extracted into a routine that can be shared by different parts of the application. For example, suppose
that you need to write event handlers for several dozen
TextBox controls. You could record a macro
while you write one of them. Then you could edit the macro to make it generate the others in a loop
using different control names for each event handler. You could place the bulk of the event-handling
code in a separate subroutine that each event handler would call. That would avoid the need for exten-
sive duplicated code. (In fact, you could even use the
AddHandler statement to make all the controls use
the same event handler. Then you wouldn’t even need to write all of the separate event handlers.)
Macros are also useful for manipulating the IDE and performing IDE-related tasks. For example, you can
write macros to show and hide your favorite toolbars, or to change whether the current file is opened
read-only.
Customize
The Tools menu’s Customize command displays the dialog shown in Figure 1-42. On the Toolbars tab,
check the boxes next to the toolbars that you want to be visible. Click New to create a new toolbar where
you can add your favorite tools. You can leave the toolbar floating or drag it to the edge of the IDE and
dock it. If you drag it to the top, it joins the other toolbars.
Figure 1-42: The Customize dialog’s Toolbar tab lets you
determine which toolbars are visible.
40
Chapter 1
571982 ch01_2.qxd 1/19/06 1:16 PM Page 40