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 box shown in Figure 1-40. On the Toolbars
tab, select the check 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.
Click the Commands tab to see a list of categories as shown in Figure 1-41. Select a category on the left. Then
click and drag a command from the list on the right. If you drop the command on a toolbar, the command is
added to the toolbar. Hover over a menu to open the menu so that you can drop the command in it.
Figure 1-40: The Customize dialog box’s Toolbars tab lets
you determine which toolbars are visible.
41
Chapter 1: IDE
37055c016.qxd 4/8/07 12:46 PM Page 41