Visual Basic 2005 New Function Reviews - Insert Codes

zhaozj2021-02-16  96

Keywords: VB2005 VB.Net Whidbey VB8.0

One of Visual Basic 2005 attractive places is that it has significantly increased development efficiency, and one of them is the insertion code segment to be introduced in this issue. The code snippet is familiar, it is some common short code. We often encounter some recurring code snippets, such as Try ... catch blocks, operation strings, and code access registry, etc. Every time you enter these code is very troublesome, because most of you use most, only a few places have changed, but you must enter. Visual Basic 2005 adds the "Insert Code Dischart" function, you can use the mouse to gently, insert the code snippet we need. Visual Basic 2005 has built a large number of pieces, so when we encounter our unfamiliar tasks, you can first look at what is available, it can be used, it is very convenient!

First let's see how to insert the code snippet, click the right mouse button where you want to insert the pieces, then select "Insert Snippet", as shown in the figure:

Next, a menu that selects the code snippet class will pop up. There is a fairly rich category available, such as access data, network connection, Visual Basic language, and Windows operating systems, and more. as the picture shows:

There are a lot of pieces under each category, and the contents of the clip are designed to play music, read XML files, traverse form controls, and more. as the picture shows:

Now we insert a piece of step, such as "seeking two dates," this is a quite common problem on a network. After inserting a piece, display the following code:

'Click for more:' ms-help://ms.vscc.v80/ms.msdnqtr.80.en/commoner/redir/redirect.htm? Keyword = "688f80b8-002b-49eb-833e-738041b81508" DIM Olddate As Date = # 1/1/2002 # Dim newDate As Date = NowDim differenceInDays As Long = DateDiff (DateInterval.Day, oldDate, newDate) Dim spanFromDays As TimeSpan = New TimeSpan (CInt (differenceInDays), 0, 0, 0)

There are several quite interesting places, first of all the comments contain links to this segment help, if you have questions about this piece, you can view your help from the link (how thoughtful design). Note that there are two yellow areas in the code, which are an area of ​​replaceable code. Click the Tab key and the cursor will automatically jump between all replaceable locations. This can quickly replace these regions into their own content. These replacement areas can remain alternative for a long time.

The interior can be inserted inside the process and the insertable piece inserted in the class / structure declaration area or namespace is not the same. For example, this piece below can only be inserted in the area of ​​the declaration area, and its function is to respond to information on system desktop changes:

'Click for more:' ms-help: //ms.vscc.v80/ms.msdnqtr.80.en/commoner/redir/redirect.htm? Keyword = "2E578CF5-B675-4FFE-A91F-17BE0015DF36" 'private SUB HookUpEvent () AddHandler Microsoft.Win32.SystemEvents.UserPreferenceChanged, _ AddressOf UserPreferenceChangedSubEnd SubPrivate Sub UserPreferenceChangedSub (ByVal sender As System.Object, _ ByVal e As Microsoft.Win32.UserPreferenceChangedEventArgs) If (e.Category = Microsoft.Win32.UserPreferenceCategory.Desktop) The feature of this code in the END IFEND SUB ("Desktop Changd.") End IFEND SUB This code is very difficult to write. If you don't insert a piece, I don't know how much effort is expected. In addition to the built-in fragment, we often need to insert the code you want. For example, for me, I often need to write a piece piece that encapsulates the property of the property. For this requirement, Visual Basic 2005 also provides the "Creating Code Dischart". As shown in the figure, it is necessary to make a piece of code, and then select "Create Snippet" function from the context menu.

Next, we can set information such as the replacement area in the clip designer set, and the category, such as the figure:

All insertable pieces are essentially a small XML code. This feature has not been completed in the current version of the Visual Studio 2005 preview version, we look forward to better performance in official versions.

转载请注明原文地址:https://www.9cbs.com/read-12198.html

New Post(0)