Viết Macros Khi các tính năng năng suất mà tàu với VS và những đoạn tùy chỉnh không cung cấp cho bạn đủ năng lượng, các bước tiếp theo là xem xét việc tạo ra một vĩ mô, mà là một bộ lặp lại các hành động mà bạn có thể ghi lại và chạy lại nhiều lần | 360 Microsoft Visual Studio 2010 A Beginner s Guide Writing Macros When the productivity features that ship with VS and custom snippets don t give you enough power the next step is to consider creating a macro which is a repeatable set of actions that you can record and re-run multiple times. An example of when a macro is useful is whenever you find yourself continuously repeating the same set of actions in VS. This section will show you how to create and run a macro that uses VS features to create a customized block of code for validating strings. Recording a Macro When creating business objects it s common to validate input parameters to ensure they are valid. One such validation is enforcing that calling code pass a required parameter. The example in this section shows you how to write a macro for validating that a stringtype parameter is not null empty or white space such as a space or tab . To get started create a new Console project and add a Class file with the following method to the project which simulates adding a new customer C using System class Customer public int AddNewCustomer string firstName string lastName int newCustID 0 Logic to add customer return newCustID VB Public Class Customer Function AddNewCustomer ByVal firstName As String ByVal lastName As String As Integer Dim newCustID As Integer 0 Logic to add customer Chapter 12 Customizing the Development Environment 361 Return newCustID End Function End Class The point of interest in the AddNewCustomer method is the firstName and lastName parameters. Whenever working with data you ll usually want to ensure that input data is legal. When user input is being processed it s common to get bad information even if you have good input validation in your user interface code. For example the following code calls the preceding AddNewCustomer method passing in bad data as arguments C class Program static void Main string firstName Joe string lastName null Customer cust new Customer .