A powerful comment on macros

Source: Internet
Author: User

Today, I mentioned the code comments in vs in a video from instructor Niu. There are a lot of comments on the Internet. I have also done this before, that is, how to follow the steps in a machine-like manner. I have never thought about more, so I have to repeat Baidu again this time. The connection address. The procedure is detailed.
Two comments about vs: the code for template modification and the macro project for template modification. In my opinion, the first method is relatively rigid. From the perspective of modification, it is not easy to modify. If we want to modify it, we need to first find the location of the file and then modify it, the workload for modification is very large, such as class templates, interface templates, and form templates. You can imagine the workload of modifying other languages after a language is modified. The second method seems to be more troublesome, but it can improve our efficiency.

First, let's briefly talk about the definition of macros. Macros in computer terms are like this. Some commands are organized together to complete a specific task as a separate command. In Microsoft word, macros are defined as: "macros are a series of word commands that can be organized together as independent commands. Why are macros used, because it makes our daily work easier. Macros are abstract text patterns that are replaced by a series of predefined rules. Macro purpose? It is a sequence that is frequently used automatically or obtains a more powerful abstract capability.

Macro definition can prevent errors, improve portability, readability, convenience, etc. I have learned how to use macro definition in c and c, which is also simple to use. Macros can be simply understood as a "function". The macro project in vs is similar to that in Excel word (both of which are from Microsoft ), ALT + F8 shows our macro project and project resource manager. We can create our own function module on the vs tool -- macro -- new macro project to add comments. We can see that the code for writing macro projects is similar to our VB.net, VBA language. We can add items in the macro project, including templates, classes, and code files. Here we add a template to give the template a unique name that identifies its characteristics, for example, I want to add a comment to the C # header file, so the template project is named CSharp_HeadFileNote, and then the code is written, so I will take the recently shared senior class in our senior class group. net coding specification.

Specific Code:
Public Module HeadFileNoteCSharp
Sub DocumentFileHeader ()
Dim doc As Document
Dim docName As String
Dim companyName As String = "information technology advanced team 3"
Dim authorName As String = ""
 
'Dim copyrightText As String = String. Format ("Copyright (c) {0} {1}. All rights reserved.", Date. Now. Year, companyName)
 
'Get the file name from the program
Doc = DTE. ActiveDocument
 
'Get the name of the current editing class
DocName = doc. Name
 
'Add the focus to the file header
DTE. ActiveDocument. Selection. StartOfDocument ()
 
'Add a copyright and author description
DTE. activeDocument. selection. text = "/************************************ * ************ "'Add the desired symbols and text in the String type"
DTE. ActiveDocument. Selection. NewLine () 'add an empty row
DTE. ActiveDocument. Selection. Text = "Author:" + authorName
DTE. ActiveDocument. Selection. NewLine ()
DTE. ActiveDocument. Selection. Text = "group:" + companyName
DTE. ActiveDocument. Selection. NewLine ()
DTE. ActiveDocument. Selection. Text = "Description :"
DTE. ActiveDocument. Selection. NewLine ()
DTE. ActiveDocument. Selection. Text = "creation Date:" + String. Format ("{0: D}", Date. Now + Now. TimeOfDay)
DTE. ActiveDocument. Selection. NewLine ()
DTE. ActiveDocument. Selection. Text = "version number: V 1.00"
DTE. ActiveDocument. Selection. NewLine ()
DTE. activeDocument. selection. text = "************************************* *********/"
 
 

End Sub
 
 

End Module

The most important thing is that vs provides us with a quick way to call macros. We can add shortcuts to every self-compiled macro module to make it easy to use.
In vs, enter our keyword in "display command inclusion", select the shortcut key of the command, select the application scope of the shortcut key, and execute the assignment of the shortcut key, in this way, you can call our macro project. We can write different macro projects for annotations in different languages, and then customize different shortcut keys, so we don't need to modify the template of the newly created items in.
The result is as follows.

Writing this reminds me that it is similar to the stored procedure in SQL. I write a series of functional statements together, name them, and call them again. From a rough perspective, they are similar, but they are very different.
Author: xhf55555

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.