VC语言

本类阅读TOP10

·VC++ 学习笔记(二)
·用Visual C++打造IE浏览器(1)
·每个开发人员现在应该下载的十种必备工具
·教你用VC6做QQ对对碰外挂程序
·Netmsg 局域网聊天程序
·Windows消息大全
·VC++下使用ADO编写数据库程序
·VC++学习笔记(四)
·非法探取密码的原理及其防范
·怎样在VC++中访问、修改注册表

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
仿照VC.NET的选择行注释宏

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

联系方式:[email protected]

==========================================================================
Sub BackSlashCommentOut()
'DESCRIPTION: Comment several selected rows of codes using double-backslash

'开始定制注释宏
  Dim win
  set win = ActiveWindow
  'Added by cadinfo, 2002,6,1 窗口关闭时无法使用宏,微软有几个自带的宏存在BUG
  if VarType(win)=vbObject Then Exit Sub
  if win.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.Selection.CurrentLine
   
    '判断是否为空,空退出宏
   
    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

      '注释方式1 反斜杠backslash "//CMT"

      '---------处理开始----------------
      '直到回车符=0
      Do While Instr (CmtBlock, vbLf) <> 0
        TmpRow = Left(CmtBlock, Instr(CmtBlock, vbLf))
        If Instr(TmpRow, CommentType) = 0 Then  ' 如果没有注释标志,则添加注释
        '添加注释标志"//CMT "
          TmpBlock = TmpBlock + CommentType + TmpRow
        Else             ' 如果有注释标志,则删除注释
          TmpBlock = TmpBlock + Mid (TmpRow, Instr(TmpRow, CommentType)+Len(CommentType), Instr(TmpRow, vbLf))
        End If
        '返回右边的字符串,长度=Len(CmtBlock)-Instr(CmtBlock, vbLf)
        CmtBlock = Right(CmtBlock, (Len(CmtBlock)-Instr(CmtBlock, vbLf)))
      Loop

      '最后一行如果没有选中回车,则在行首添加注释标志"//CMT "
      if(Len(Trim(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)  '拼接字符串
      '---------到此处理完毕----------------

      'ActiveDocument.Selection.Delete
      ActiveDocument.Selection = CmtBlock
      ActiveDocument.Selection.GotoLine LineNum
   
      '添加语句选择处理行   (ActiveDocument.Selection.SelectLine)
'     StartLine = ActiveDocument.Selection.TopLine
'     EndLine = ActiveDocument.Selection.BottomLine
'     For i = StartLine To EndLine
'       ActiveDocument.Selection.GoToLine i, dsSelect
'     Next

      '另外一种注释方式
      'ActiveDocument.Selection = "/*" + ActiveDocument.Selection + "*/"
    Else
      MsgBox("File not supported or unknow error!")
    End If
  End If
'结束定制注释宏
End Sub
========================================================

这次修改,完成了Toogle的功能,并且指出VS自带的一些宏中存在BUG,

在无文档打开时调用宏会报错,作者添加了判断语句,屏蔽了这个问题。




相关文章

相关软件