VS2003 uses macro to increase efficiency

xiaoxiao2021-03-06  36

The code is more difficult, it will inevitably have a lot of repetitive work, such as each member function and parameter write instruction document, etc., for this purpose, macro can improve efficiency. Below is the macro I wrote and some improved, you can add to VS2003 Inside the macro manager, you can use it.

Option Strict Off

Option expendit off

Imports envdte

Imports system.diagnostics

Imports system.windows

Imports System.Windows.Forms

Imports system

Imports system.collections.specialized

Public Module Ownmacros

'Paste text in front of the text selected

Public Sub Pasteatbegin ()

Pastetext (0)

End Sub

'The last paste of the selected text

Public Sub Pasteatend ()

Pastetext (1)

End Sub

'Paste the text before and after the selected text

Public Sub Pasteatbenginend ()

Pastetext (2)

End Sub

'Paste text

Private sub pastetext (byval position as integer)

DIM BEGINLINE, ENDLINE AS INTEGER

DIM ObjtextSelection As TextSerection

DIM I as integer

ObjtextSelection = ctype (DTE.ActiveDocument.selection (), envdte.textselection

Beginline = ObjtextSelection.Anchorpoint.Line

Endline = objtextSelection.bottompOint.Line

For i = beginline to endline

ObjtextSelection.gotoline (i, false)

IF position = 0 or position = 2 THEN

ObjtextSelection.Startofline (vSstartoflineOptions.vsstartoflineOptionsfirsttext)

ObjtextSelection.Paste ()

END IF

If position = 1 or position = 2 THEN

ObjtextSelection.endofline ()

ObjtextSelection.Paste ()

END IF

NEXT

End Sub

'Paste multiple lines of text

Sub multilinepaste ()

DIM BEGINROW, ENDROW AS INTEGER

DIM ObjtextSelection As TextSerection

DIM I as integer

DIM Value As New StringCollection

ObjtextSelection = CType (DTE.ActiveDocument.selection, Envdte.TextSerection)

BeginRow = objtextSerection.Anchorpoint.Line

Endrow = objtextSelection.bottompoint.Line

IF BeginRow

For i = beginrow to endrow

ObjtextSelection.gotoline (i, false)

ObjtextSelection.Startofline (vSstartoflineOptions.vsstartoflineOptionsfirsttext)

ObjtextSelection.endofline (true) value.add (objtextSelection.text)

ObjtextSelection.delete ()

NEXT

ObjtextSelection.gotoline (BeginRow, False)

ObjtextSelection.Paste ()

For i = beginrow to endrow

ObjtextSelection.gotoline (i, false)

ObjtextSelection.Startofline (vSstartoflineOptions.vsstartoflineOptionsfirsttext)

ObjtextSelection.Insert (Value.Item (i - beginRow))

ObjtextSelection.insert ("")

NEXT

Value.clear ()

END IF

End Sub

SUB MULTILINEREPERT ()

DIM BEGINROW, ENDROW AS INTEGER

DIM ObjtextSelection As TextSerection

DIM I as integer

ObjtextSelection = CType (DTE.ActiveDocument.selection, Envdte.TextSerection)

BeginRow = objtextSerection.Anchorpoint.Line

Endrow = objtextSelection.bottompoint.Line

IF BeginRow

For i = beginrow to endrow

ObjtextSelection.gotoline (i, false)

ObjtextSelection.Startofline (vSstartoflineOptions.vsstartoflineOptionsfirsttext)

ObjtextSelection.endofline (TRUE)

ObjtextSelection.copy ()

ObjtextSelection.endofline (false)

ObjtextSelection.Insert (Microsoft.visualBasic.Constants.vbtab Microsoft.VisualBasic.Constants.vbtab)

ObjtextSelection.Paste ()

NEXT

END IF

End Sub

'Adding VB comments for selecting text

Public Sub Addvbcomment ()

AddcommentInfo (0)

End Sub

'Add a VC annotation for the selected text

Public Sub AddVCComment ()

AddcommentInfo (1)

End Sub

'Add an comment text

Private sub addcommentinfo (Byval Type as integer)

DIM ObjtextSelection As TextSerection

DIM Comment As String

Dim text as string

ObjtextSelection = CType (DTE.ActiveDocument.selection, Envdte.TextSerection)

Text = ObjtextSelection.Text

If Type = 0 THEN

Comment = "'"

END IF

If Type = 1 THEN

Comment = "//"

END IF

ObjtextSelection.Lineup ()

ObjtextSelection.Newline () objtextSelection.text = Comment "

"

ObjtextSelection.newline ()

ObjtextSerection.Text = Comment Text

ObjtextSelection.newline ()

ObjtextSelection.Text = Comment ""

End Sub

Public Sub Clearscript ()

DIM BeginPoint As VirtualPoint

DIM Endpoint As VirtualPoint

DIM ObjtextSelection As TextSerection

DIM B, E AS INTEGER

Dim Bline, Eline As Integer

DIM FINDRESULT As Boolean

ObjtextSelection = CType (DTE.ActiveDocument.selection, Envdte.TextSerection)

'objtextSelection.Startofdocument (false)

FindResult = TRUE

While FindResult = TRUE

FindResult = FALSE

If ObjtextSelection.FindText ("

Beginpoint = ObjtextSelection.Anchorpoint

Bline = beginpoint.Line

B = beginpoint.absolutecharoffset

Else

Exit while

END IF

IF ObjtextSelection.FindText ("/ script>", vsfindoptions.vsfindOptionsmatchWholeWord) THEN

Endpoint = ObjtextSelection.bottompOint

Eline = Endpoint.Line

e = endpoint.absolutecharoffset

FindResult = TRUE

END IF

IF (Bline <= Eline) and ((Eline - Bline) <= 3) THEN

ObjtextSelection.MovetoabsoluteOffset (b)

ObjtextSelection.MovetoabsoluteOffset (e, true)

ObjtextSelection.delete ()

Else

'ObjtextSelection.Wordright (false)

ObjtextSelection.Movetopoint (ObjTextSelection.bottompOint)

END IF

End while

'DTE.ActiveDocument.save ()

DTE.ActiveDocument.Close (vssavechanges.vssavechangesyes)

End Sub

'Add final modification information

Public Sub AddlastModify ()

DIM ObjtextSelection As TextSerection

DIM Comment As String

Comment = lineorientedcommentStart ()

If Comment = "" "

Comment = "-" END IF

ObjtextSelection = CType (DTE.ActiveDocument.selection, Envdte.TextSerection)

ObjtextSelection.StartofDocument (false)

ObjtextSelection.newline ()

ObjtextSelection.text = Comment "########################################################################################################################################################################################################################################################### ###### "

ObjtextSelection.newline ()

ObjtextSelection.Text = Comment "Modification:"

ObjtextSelection.newline ()

ObjtextSelection.Text = Comment "Modification Time:"

ObjtextSelection.Text = system.datetime.now.tolongdateString () " system.datetime.now.tolongtimeString ()

ObjtextSelection.newline ()

ObjtextSelection.text = Comment "########################################################################################################################################################################################################################################################### ###### "

ObjtextSelection.newline ()

ObjtextSelection.newline ()

End Sub

'Add code version information

Public Sub AddVersionInfo ()

DIM ObjtextSelection As TextSerection

DIM Comment As String

Comment = lineorientedcommentStart ()

If Comment = "" "

Comment = "-"

END IF

ObjtextSelection = CType (DTE.ActiveDocument.selection, Envdte.TextSerection)

ObjtextSelection.StartofDocument (false)

ObjtextSelection.newline ()

ObjtextSelection.text = Comment "########################################################################################################################################################################################################################################################### ###### "

ObjtextSelection.newline ()

ObjtextSelection.Text = Comment

ObjtextSelection.newline ()

ObjtextSelection.Text = Comment "version:"

ObjtextSelection.newline ()

objTextSelection.Text = comment "Author:"

ObjtextSelection.newline ()

ObjtextSelection.Text = Comment "Description:"

ObjtextSelection.newline ()

ObjtextSelection.Text = Comment "Last modified:"

ObjtextSelection.Text = system.datetime.now.tolongdateString () " system.datetime.now.tolongtimeString () objtextSelection.newline ()

ObjtextSelection.Text = Comment

ObjtextSelection.newline ()

ObjtextSelection.text = Comment "########################################################################################################################################################################################################################################################### ###### "

ObjtextSelection.newline ()

ObjtextSelection.newline ()

ObjtextSelection.newline ()

End Sub

Private Sub CommentCodetype (Byref Celttype as CodeType)

Dim Celt as cotElement

DIM EP as EditPoint = CeltType.getStartPoint (vscmpart.vscmparthead) .createeditpoint ()

DIM CommentStart As String = lineorientedcommentStart ()

IF (CommentStart.length = 2) THEN

CommentStart = CommentStart & CommentStart.Chars (1) & ""

Elseif (CommentStart.length = 1) THEN

CommentStart = CommentStart & CommentStart.chars (0) & CommentStart.Chars (0) & ""

END IF

Try

DTE.undocontext.Open ("Insert Doc Comments")

For Each Celt in Celttype.members

'By taking the text of the line to determine if the member is commented.

Ep.movetopoint (Celt.getStartPoint (vscmpart.vscmparthead))

EP.LineUP ()

Dim alreadycheck as string = trim (ep.getlines (ep.line, ep.line 1))

IF (alleadycheck = trim (commentstart) THEN

Goto next_loop

END IF

IF (Celt.kind = vscmelement.vscmelementfunction) THEN

DIM Codefun as codefunction = CELT

Ep.movetopoint (Codefun.getStartPoint (vscmpart.vscmparthead))

Dim params as coteelements = codefun.parameters

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

EP.LineUP ()

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart & "

")

Ep.Insert (Microsoft.visualBasic.Constants.vbcrlf) ep.insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart & "Summary:" & Celt.name & ".")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart & "")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart)

Dim Celt2 as cotElement

DIM CP as CodeParameter

For Each Celt2 in Params

CP = CELT2

Ep.insert (" ")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart)

Next 'Param

END IF 'WE HAVE A FUNCTION

IF (celt.kind = vscmelement.vscmelementproperty) THEN

DIM CodeProp as coteproperty = CELT

Ep.MoveTopoint (CodeProp.getStartPoint (vscmpart.vscmparthead))

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

EP.LineUP ()

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart & "")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.visualBasic.Constants.vbtab & CommentStart & "Description:" & Celt.name & ".")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.visualBasic.Constants.vbtab & CommentStart & "")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart)

END IF

IF (Celt.kind = vscmelement.vscmelementvariable) THEN

Dim code as codevariable = CELT

Ep.movetopoint (code.getstartpoint (vscmpart.vscmparthead) ep.insert (Microsoft.VisualBasic.Constants.vbcrlf)

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

EP.LineUP ()

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart & "Member>")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.visualBasic.Constants.vbtab & CommentStart & "Description:" & Celt.name & ".")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart & "")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart)

END IF

IF (Celt.kind = vscmelement.vscmelementstruct) THEN

DIM code as cotStruct = CELT

Ep.Movetopoint (Code.getStartPoint (vscmpart.vscmparthead))

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

EP.LineUP ()

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart & "Structure>")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.visualBasic.Constants.vbtab & CommentStart & "Description:" & Celt.name & ".")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart & "")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart)

END IF

Next_loop:

Next 'code ELT MEMBER

Finally

DTE.undocontext.close ()

END TRY

End Sub

'Add Chinese comment for VB code

Sub insertchscomments ()

Dim Projitem as ProjectItem = DTE.ActiveDocument.ProjectItem

Dim filecm as filecodemodel = projitem.filecodemodeldim Celt As CodeElement

DIM CELTTYPE AS CODETYPE

DIM I as integer

DIM J AS INTEGER

For i = 1 to filecm.codeelements.count

Celt = filecm.codeelements.Item (i)

IF (Typeof Celt Is Codenamespace) THEN

DIM TT AS CODENAMESPACE

Tt = CELT

For j = 1 to tt.members.count

'Celt = Celt.members.Item (1)

Celt = tt.members.Item (j)

IF (Typeof Celt Is Codetype) THEN

Celttype = ctype (CELT, CODETYPE)

Else

Throw new Exception ("Didn't Find A Type Definition As First")

END IF

CommentCodetype (CeltType)

NEXT

Else

IF (Typeof Celt Is Codetype) THEN

Celttype = ctype (CELT, CODETYPE)

Else

Throw new Exception ("Didn't Find A Type Definition As First")

END IF

CommentCodetype (CeltType)

END IF

NEXT

End Sub

Private subinsertdocchscomments ()

Dim Projitem as ProjectItem = DTE.ActiveDocument.ProjectItem

Dim filecm as filecodemodel = projitem.filecodemodel

Dim Celt as cotElement = filecm.codeElements.Item (1)

DIM CELTTYPE AS CODETYPE

IF (Typeof Celt Is Codenamespace) THEN

Celt = Celt.members.Item (1)

END IF

IF (Typeof Celt Is Codetype) THEN

Celttype = ctype (CELT, CODETYPE)

Else

Throw new Exception ("Didn't Find A Type Definition As First")

END IF

DIM EP as EditPoint = CeltType.getStartPoint (vscmpart.vscmparthead) .createeditpoint ()

DIM CommentStart As String = lineorientedcommentStart ()

IF (CommentStart.Length = 2) ThencommentStart = CommentStart & CommentStart.Chars (1) & ""

Elseif (CommentStart.length = 1) THEN

CommentStart = CommentStart & CommentStart.chars (0) & CommentStart.Chars (0) & ""

END IF

Try

DTE.undocontext.Open ("Insert Doc Comments")

For Each Celt in Celttype.members

IF (Celt.kind = vscmelement.vscmelementfunction) THEN

DIM Codefun as codefunction = CELT

Ep.movetopoint (Codefun.getStartPoint (vscmpart.vscmparthead))

Dim params as coteelements = codefun.parameters

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

EP.LineUP ()

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart & "

")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart & "Summary:" & Celt.name & ".")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart & "")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart)

Dim Celt2 as cotElement

DIM CP as CodeParameter

For Each Celt2 in Params

CP = CELT2

Ep.insert ("")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart)

Next 'Param

END IF 'WE HAVE A FUNCTION

IF (celt.kind = vscmelement.vscmelementproperty) THEN

DIM CodeProp as coteproperty = CELT

Ep.MoveTopoint (CodeProp.getStartPoint (vscmpart.vscmparthead))

'Dim params as cotElement = codeprop.attributesep.insert (microsoft.visualbasic.constants.vbcrlf)

EP.LineUP ()

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart & "")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.visualBasic.Constants.vbtab & CommentStart & "Description:" & Celt.name & ".")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.visualBasic.Constants.vbtab & CommentStart & "")

Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

Ep.Insert (Microsoft.VisualBasic.Constants.vbtab & CommentStart)

'Dim Celt2 as cotElement

'DIM CP as CodeParameter

'For Each Celt2 in Params

'Cp = celt2

'Ep.insert ("")

'Ep.insert (Microsoft.visualBasic.Constants.vbcrlf)

'Ep.insert (Microsoft.visualBasic.Constants.vbtab & CommentStart)

'Next

END IF

Next 'code ELT MEMBER

Finally

DTE.undocontext.close ()

END TRY

End Sub

'Return Note Type

Function LineorientedCommentStart (optional byval Doc as document = nothing) AS STRING

IF (doc is nothing) THEN

DOC = DTE.ActiveDocument

END IF

DIM EXT AS STRING = doc.name

IF (EXT.EndSwith)).

Return "//"

Elseif (EXT.EndSwith (". CPP")).

Return "//"

Elseif (EXT.ENDSWITH (". H")).

Return "//"

Elseif (EXT.EndSwith)).

Return "'"

Elseif (EXT.EndSwith (". Idl")).

Return "//"

END IF

END FUNCTION

End module

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

New Post(0)