3 ide tools macros that are useful for VC

Source: Internet
Author: User
Three macro tools I used in vc6 Favorites

New article: Status Bar (3/3)-teststatusbar. Java implemented in Java | old article: Create a class for the filefilter object used by jfilechooser implemented by RegEx


Although
However, the time to use VC is not short, but I recently noticed that the VC can also customize macros, such as Word and execel. I wrote the following three, which has a good effect and can greatly prolong the service life of the keyboard. Introduction
I hope you can help me. 1. Add function comment Blocks
In VC, the macro file sample. DSM has an addfunctiondescription macro which can also add comments to the function. However, the format is relatively simple and it is very troublesome to modify.
Therefore, I wrote another macro based on my own annotation format, and only by simply modifying the data in the program, you can easily change it to the annotation format you need (see comments in the code, attached ). Below is when
Before running:

/*************************************** ***************************************
Function: funname
Purpose:
Parameters:
Type1 arg1-
Type2 arg2arg2-
Type3 arg3-
Return type:
Funtype comments:
History:
Date Author comment 2005-4-18 Jason created ********************************** **************************************** ****/
Funtype funname (type1 arg1, type2 arg2arg2, type3 arg3)

Note: You must select the entire line for use.

2. Comment the code and cancel the code comment

3. How to Use

1) create a file, such as "mymacros. DSM, copy the code to the file, and put the file in the "C:/program files/Microsoft Visual Studio/common/msdev98/macros" directory.
2) choose VC menu> Tools> customization, select "additional items and macro files", and select "mymacors"
3) set the shortcut key. Select "keyboard", select "macros" in "category" ComboBox, select the corresponding macro in the command, and set the shortcut key
4) set the menu button. Select "command", select "macros" in "category" ComboBox ", select the corresponding macro in" commands ", and drag it to the existing toolbar on the IDE interface, select an appropriate image.
5) choose one of Steps 3 and 4.

4. In the code, the parsetoarray function is transplanted from PFC and is useful in character processing. It is often used in Excel.

'------------------------------------------------------------------------------
'File Description: new macro file
'------------------------------------------------------------------------------

Sub comment ()
'Description: comment out the selected code line.
Dim top, bottom, line
Dim startcol, Col
 
Startcol= 1000

With activedocument. Selection

Top =. topline
Bottom =. Bottomline

For line = top to bottom
. Gotoline line, dsselect
. Selectline
 
. Replacetext "/*","/&*"
. Replacetext "*/","*&/"

. Startofline dsfirsttext
Col =. currentcolumn

If startcol> Col then
Startcol = col
End if
Next
 
For line = top to bottom
. MoveTo line, startcol
'Msgbox. Text
. Text = "//"
Next

End
End sub

Sub Recomment ()
'Description: uncomment the selected code line.
Dim top, bottom, line
Dim startcol, Col

With activedocument. Selection

Top =. topline
Bottom =. Bottomline

For line = top to bottom
. Gotoline line, dsselect
. Selectline
. Replacetext "/&*","/*"
. Replacetext "*&/","*/"

. Startofline dsfirsttext
. Selectline
Pos = instr (. Text ,"//")
If POS> 0 then
. Cancel
. Startofline dsfirsttext
. Delete 2
. Charright dsextend
If. Text = "" then
. Delete
End if
End if
Next

End
End sub

Sub addfundescription ()
'Description: adds a comment block for the selected function.
Dim text, funheader, funparms, doctl, author
Dim strfunname, strfuntype
Dim TMP (), strparms ()
Dim funname, retruntype, parameters, history
 
Doctl = activedocument. tabsize 'tab size, which is used to align the parameter list in this program.
Author = "Jason" 'Your English name. Please change it to your name.

'Desc' controls the format of the comment block. You can change the comment block to the format you need.
'After modification, pay attention to modifying the upper boundary of DESC, and make corresponding modifications to the subsequent four parameters.
Dim DESC (15)
DESC (0) = "/************************************* **************************************** *"
DESC (1) = "" 'empty line
DESC (2) = "function:" + vbtab "function name is added here
DESC (3) = ""
DESC (4) = "Purpose:" + vbtab
DESC (5) = ""
DESC (6) = "parameters :"
DESC (7) = vbtab + vbtab. The parameter list is added here.
DESC (8) = ""
DESC (9) = "return type:" 'function type is added here
DESC (10) = vbtab + vbtab
DESC (11) = "Comments:" + vbtab
DESC (12) = ""
DESC (13) = "History:" + vbtab + "date" + vbtab + "author" + vbtab + "comment"
DESC (14) = vbtab + vbtab
DESC (15) = "************************************** **************************************** /"

Funname = 2' place the row of the function name
Retruntype = 9' place row of Function Type
Parameters = 7' place the starting line of the parameter list
History = 14' place the line of History

With activedocument. Selection
 
'Get function info
TEXT = trim (. Text)
If text = "" Then exit sub

Replaceall text, vbtab ,""
 
If getstringbetween (text, "", "(") = "" Then exit sub

Parsetoarray getstringbetween (text, "", "("), "", TMP, true
If ubound (TMP) = 0 Then exit sub

Strfunname = TMP (ubound (TMP ))
For I = 0 to ubound (TMP)-1
Strfuntype = strfuntype + TMP (I) + ""
Next

Parsetoarray getstringbetween (text, "(", ")"), ",", strparms, true

. Startofline
. Newline
. Lineup
. Text = DESC (0)

For line = 1 to ubound (DESC)
. Newline
. Startofline
If line = funname then
. Text = DESC (line) + strfunname
Elseif line = retruntype then
. Text = DESC (line) + strfuntype
Elseif line = parameters then
Dim maxlen, maxtab
For I = 0 to ubound (strparms)
Strparms (I) = trim (strparms (I ))
If maxlen <Len (strparms (I) then
Maxlen = Len (strparms (I ))
End if
Next

Maxtab = maxlen/doctl

For I = 0 to ubound (strparms)-1
. Text = DESC (line) + strparms (I) + String (maxtab-(LEN (strparms (I)/doctl), vbtab) + vbtab + "-"
. Newline
. Startofline dsfirstcolumn
Next
. Text = DESC (line) + strparms (I) + String (maxtab-(LEN (strparms (I)/doctl), vbtab) + vbtab + "-"
Elseif line = history then
. Text = DESC (line)
. Text = formatdatetime (date, vb1_date)
. Text = + vbtab + author + vbtab + "created"
Else
. Text = DESC (line)
End if
Next

End

End sub

Function parsetoarray (byval as_source, byval as_delimiter, as_array (), bpreventrepeat)

Dim ll_dellen, ll_pos, ll_count, ll_start, ll_length
Dim ls_holder

'Check for null
If isnull (as_source) or isnull (as_delimiter) then
Parsetoarray = NULL
End if

'Check for at leat one entry
If trim (as_source) = "" then
Parsetoarray = 0
End if

'Get the length of the delimeter
Ll_dellen = Len (as_delimiter)

Ll_pos = instr (ucase (as_source), ucase (as_delimiter ))

'Only one entry was found
If ll_pos = 0 then
Redim as_array (0)
As_array (0) = as_source
Parsetoarray = 1
End if

'More than one entry was found-loop to get all of them
Ll_count =-1
Ll_start = 1
Do While ll_pos> 0

'Set current entry
Ll_length = ll_pos-ll_start

If not bpreventrepeat or ll_length> 0 then
Ls_holder = mid (as_source, ll_start, ll_length)

'Update array and counter
Ll_count = ll_count + 1
Redim preserve as_array (ll_count)
As_array (ll_count) = ls_holder
Else
End if
'Set the new starting position
Ll_start = ll_pos + ll_dellen

Ll_pos = instr (ll_start, ucase (as_source), ucase (as_delimiter ))
Loop

'Set last entry
Ls_holder = mid (as_source, ll_start, Len (as_source ))

'Update array and counter if necessary
If Len (ls_holder)> 0 then
Ll_count = ll_count + 1
Redim preserve as_array (ll_count)
As_array (ll_count) = ls_holder
End if

'Parsetoarray = the number of entries found
Parsetoarray = ll_count

End Function

Function getstringbetween (byval STR, byval strstart, byval strend)
Dim pos1, pos2, POS

If STR = "" then
Getstringbetween = ""
Exit Function
End if

If strstart = "" then
Pos1 = 1
Else
Pos1 = instr (STR, strstart) + Len (strstart)
End if

Pos = instr (pos1, STR, strend)
If POS> 0 then
Do While POS> 0
Pos2 = POS
Pos = instr (Pos + 1, STR, strend)
Loop
Else
Pos2 = Len (STR)
End if

Getstringbetween = mid (STR, pos1, pos2-pos1)
End Function

Function replaceall (STR, rep, repwith)
Do While instr (STR, Rep)> 0
STR = Replace (STR, rep, repwith)
Loop
End Function

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.