可以把下面的代码存为Commentline.dsm,放到Visual Fortran的Common\msdev98\
macros目录下面。在Visual Fortran集成编译环境下,首先选择菜单Tools-> Customiz
e-> Add-ins and Macro Files,选择Commentline,再点击close按钮。然后用鼠标选择
若干行文本,选择菜单Tools->Macro,选择Macro Name为CommentLine或UnCommentLine
,再点击Run按钮,就可以分别实现注释所选择的文本行和删除所选择的文本行首的“!
”了。在UnCommentLine中,如果有的文本行行首没有“!”,则该行不受影响。
    另外,可以为这两个宏定义快捷键,以方便使用。方法如下:选择菜单Tools->Cus
tomize->Keyboard,在Category中选择Macros,在Commands中会出现CommentLine和UnC
ommentLine,首先选择CommentLine,点击Press new shortcut框,再按下希望定义的快
捷键,最后点击Assign按钮;UnCommentLine的快捷键的定义方法相同。
'-----------------------------------------------------------------------
'FILE DESCRIPTION: 注释若干行;去掉若干行的注释
'-----------------------------------------------------------------------
Sub CommentLine()
'DESCRIPTION: 注释若干行
    Dim EndLine, CurrLine
    EndLine=ActiveDocument.Selection.BottomLine
    ActiveDocument.Selection.StartOfLine
    CurrLine=ActiveDocument.Selection.CurrentLine
    while ( CurrLine<=EndLine )
        ActiveDocument.Selection.SelectLine
        ActiveDocument.Selection = "!" + ActiveDocument.Selection
        CurrLine=ActiveDocument.Selection.CurrentLine
    wend
End Sub
Sub UnCommentLine()
'DESCRIPTION: 去掉若干行的注释
    Dim EndLine, CurrLine, CurrText
    EndLine=ActiveDocument.Selection.BottomLine
    ActiveDocument.Selection.StartOfLine
    CurrLine=ActiveDocument.Selection.CurrentLine
    while ( CurrLine<=EndLine )
        ActiveDocument.Selection.SelectLine
        CurrText = ActiveDocument.Selection
        if ( Left(CurrText, 1) = "!" ) then
            CurrText = Right(CurrText, Len(CurrText)-1)
            ActiveDocument.Selection = CurrText
            CurrLine=ActiveDocument.Selection.CurrentLine
        else
            CurrLine=CurrLine+1
            ActiveDocument.Selection.LineDown
            ActiveDocument.Selection.LineUp
        end if
    wend
End Sub
 
没有评论:
发表评论