Datasheet

Some examples of macros that I’ve used in the past include code that: arranges controls in unusual ways,
such as spacing picture boxes around the edge of a circle; that generates a long series of statements that
does the same thing to a collection of text values (for example, makes
Select Case statements for a
series of text values); sets up a new dialog box by creating the OK and Cancel buttons, positioning them,
setting their
DialogResult properties, and setting the form’s AcceptButton and CancelButton
properties; and building a name and address form with labels and text boxes that have appropriate
Anchor properties. Author John Mueller (www.mwt.net/~jmueller) uses similar macros to set up
dialog boxes, create standard menus, and build standard event handlers. There are other ways to do these
things, such as saving a pre-built dialog box for use as a template, or by using code snippets described
later in this chapter, but macros are quick and easy.
After you have recorded a macro, you can edit the macro’s code and make changes. For example, if you
want to run the code a certain number of times, you can include it in a
For loop. Often, a quick inspection
of the code lets you figure out how to modify the code to perform actions similar to (but not exactly the
same as) the actions you originally recorded.
Most of the commands in the macros submenu are self-explanatory. Use the Record TemporaryMacro
command to record a macro for quick temporary use. When you select this command, a small window
pops up that contains buttons you can click to suspend, finish, or cancel recording. Visual Studio saves
the commands you execute in a macro named
TemporaryMacro.
Select Run TemporaryMacro to run this macro. If you record a new
TemporaryMacro, it overwrites the
existing one without warning you. Select the Save TemporaryMacro command to rename the macro so
you can record a new
TemporaryMacro without destroying this one.
Select the Macro Explorer command to display the window shown in Figure 1-39. If you right-click a
macro, the resulting pop-up menu lets you run, edit, rename, or delete the macro. Notice the Macro
Explorer’s predefined Samples section, which contains example macros that you can use or modify
for your own use.
Figure 1-39: The Macro Explorer lets
you edit, run, and delete macros.
40
Part I: Getting Started
37055c016.qxd 4/8/07 12:46 PM Page 40