Contact: Cadinfo@263.net
============================================================================================================================================================================================================= ======================== Sub backslashcomment () 'Description: Comment several selected rows of cots using double-backslash
'Start Custom Note Macro DIM WIN SET WIN = ActiveWindow' Added by Cadinfo, 2002, 6, 1 window Closes Macro .type <> "text" Then MsgBox "This macro can only be run when a text editor window is active." else 'Define three string variable TmpBlock = "" TmpRow = "" CmtBlock = Trim (ActiveDocument.Selection) LineNum = ActiveDocument .Serection.currentline 'Judging whether it is empty, empty exits macro if (len (cmtblock = 0) THEN EXIT SUB
TypeOfFile = FileType (ActiveDocument) If TypeOfFile> 0 And TypeOfFile <5 Then If TypeOfFile> 3 Then CommentType = " 'CMT"' VBShit Else CommentType = "// CMT" 'C & C & C # & Java use the same End If
'Note Way 1 Reverse Bar Backslash "// CMT"
'--------- Processing ----------------' until the Auto-Yeth (CMTBLOCK, VBLF) <> 0 TMPROW = LEFT CMTBLOCK, INSTR (CMTBLOCK, VBLF)) IF INSTR (TMPROW, CommentType) = 0 TEN 'If there is no comment sign, add a comment' Add a comment sign "// cmt" TMPBLOCK = TMPBLOCK CommentType TMPROW ELSE 'If there is a comment sign Delete TMPBLOCK = TmpBlock MID (TmpRow, Instr (Tmprow, CommentType) Len (CommentType), INSTR (TMPROW, VBLF)) endiff 'Return to the string of the right, length = len (cmtblock) -instr (CMTBLOCK , VBLF) CMTBLOCK = Right (CMTBLOCK, (LEN (CMTBLOCK) -instr (cmtblock, VBLF))) LOOP 'Last row If you do not choose to enter, add a comment sign "// cmt" if (LEN " (CmtBlock)) <> 0) Then If Instr (CmtBlock, CommentType) = 0 Then CmtBlock = CommentType CmtBlock Else CmtBlock = Right (CmtBlock, Len (CmtBlock) - (Instr (CmtBlock, CommentType) Len (CommentType)) 1 ) End if end if cmtblock = tmpblock trim (cmtblock) 'Splic string' --------- to this processing ------------------------------------------------------------------------------------------
'ActiveDocument.Selection.Delete ActiveDocument.Selection = CmtBlock ActiveDocument.Selection.GotoLine LineNum' statement add row selection processing (ActiveDocument.Selection.SelectLine) 'StartLine = ActiveDocument.Selection.TopLine' EndLine = ActiveDocument.Selection.BottomLine 'For i = Startline to endline 'ActiveDocument.selection.gotoline I, DSSELECT' NEXT
'Another annotation mode' ActiveDocument.selection = "/ *" ActiveDocument.selection "* /" Else Msgbox ("File Not Supported or Unknow Error!") End if End If 'End Custom Comment Macro End Sub == ============================================================================================================================================================================================================= ==== This modification, completed the TOOGLE function, and pointed out that there is a bug in some macros that come with the VS.
When the macro is called when no document is opened, the author adds a judgment statement to block this problem.