VC6.0 中 添加/取消 块注释的Macro代码
SAMPLE.DSM是微软提供的样例,使用的是vb语言。其中的 CommentOut 函数,是支持块注释的,可是这种/**/的注释方式,有时候用起来不是很方便,因为两个/会因为一个/而终止。对于大块代码,使用//注释,仅需修改原样例函数中的少部分代码。
取消注释的实现,可以在注释的基础上进行修改。两个函数的源码如下:
Sub CommentOut ()
'DESCRIPTION: Comments out a selected block of text.
Dim win
set win = ActiveWindow
if win.type <> "Text" Then
MsgBox "This macro can only be run when a text editor window is active."
else
TypeOfFile = FileType(ActiveDocument)
If TypeOfFile > 0 And TypeOfFile < 5 Then 'C & Java use the same
'style of comments.
'在这里修改
'ActiveDocument.Selection = "/*" + ActiveDocument.Selection + "*/"
CommentType = "//"
StartLine = ActiveDocument.Selection.TopLine
EndLine = ActiveDocument.Selection.BottomLine
For i = StartLine To EndLine
ActiveDocument.Selection.GoToLine i
ActiveDocument.Selection.SelectLine
ActiveDocument.Selection = CommentType + ActiveDocument.Selection
Next
ElseIf TypeOfFile = 5 Then
ActiveDocument.Selection = "<!-- " + ActiveDocument.Selection + " -->"
ElseIf TypeOfFile = 6 Or TypeOfFile = 7 Then
'There is no group comment like there is in the other file types,
'so we need to iterate through each line, and prepend a ' to the line.
'Also, because VBS/DEF does not have a 'end the comment at this
'particular column' delimiter, entire lines of code must be
'commented out, not sections.
If TypeOfFile = 6 Then
CommentType = " ' "
Else
CommentType = " ; "
End If
StartLine = ActiveDocument.Selection.TopLine
EndLine = ActiveDocument.Selection.BottomLine
If EndLine < StartLine Then
Temp = StartLine
StartLine = EndLine
EndLine = Temp
End If
If EndLine = StartLine Then
ActiveDocument.Selection = CommentType + ActiveDocument.Selection
Else
For i = StartLine To EndLine
ActiveDocument.Selection.GoToLine i
ActiveDocument.Selection.S1electLine
ActiveDocument.Selection = CommentType + _
ActiveDocument.Selection
Next
End If
Else
MsgBox("Unable to comment out the highlighted text" + vbLf + _
"because the file type was unrecognized." + vbLf + _
"If the file has not yet been saved, " + vbLf + _
"please save it and try again.")
End If
End If
End Sub
Sub UndoCommentOut ()
'DESCRIPTION: Comments out a selected block of text.
Dim win
set win = ActiveWindow
if win.type <> "Text" Then
MsgBox "This macro can only be run when a text editor window is active."
else
TypeOfFile = FileType(ActiveDocument)
If TypeOfFile > 0 And TypeOfFile < 5 Then 'C & Java use the same
'style of comments.
'ActiveDocument.Selection = "/*" + ActiveDocument.Selection + "*/"
StartLine = ActiveDocument.Selection.TopLine
EndLine = ActiveDocument.Selection.BottomLine
For i = StartLine To EndLine
ActiveDocument.Selection.GoToLine i
ActiveDocument.Selection.SelectLine
'在这里修改
If(Left(ActiveDocument.Selection,2)="//") Then
ActiveDocument.Selection = Mid(ActiveDocument.Selection,3)
End If
Next
Else
MsgBox("Unable to undo comment out the highlighted text" + vbLf + _
"because the file type was unrecognized." + vbLf + _
"If the file has not yet been saved, " + vbLf + _
"please save it and try again.")
End If
End If
End Sub
最近又写了这样一个注释的代码,根据回车+//作为分隔符,直接改写选中块,添加删除都在一个函数中。只是选中时,第一行若是未从行首开始,注释//未必会在行首,难免有点美中不足
Sub Comment ( )
TmpBlock = ""
CmtBlock = ActiveDocument.Selection
TypeOfFile = FileType(ActiveDocument)
If TypeOfFile > 0 And TypeOfFile < 5 Then 'C/C++ style comment.
'Get the first two characters of the comment block.
Trim(CmtBlock)
str = vbLf + "//"
If (Left(CmtBlock,2) = "//") Then
CmtBlock = Mid(CmtBlock,3)
pos = Instr (CmtBlock,str)
If pos <> 0 Then
Do While pos <> 0
TmpBlock = TmpBlock + Left (CmtBlock, pos)
CmtBlock = Mid(CmtBlock, pos + Len(str))
pos = Instr (CmtBlock,str)
Loop
CmtBlock = TmpBlock + CmtBlock
End If
Else
CmtBlock = "//" + CmtBlock
pos = Instr (CmtBlock, vbLf)
Do While pos <> 0
TmpBlock = TmpBlock + Left (CmtBlock, pos)_
+ "//"
CmtBlock = Mid(CmtBlock, pos + 1)
pos = Instr (CmtBlock, vbLf)
Loop
CmtBlock = TmpBlock + Trim(CmtBlock)
If(Right(CmtBlock,3) = str) Then
CmtBlock = Left(CmtBlock,Len(CmtBlock) - 3)
CmtBlock = CmtBlock + vblf
End If
End If
ActiveDocument.Selection = CmtBlock
Else
MsgBox "This macro does not work on this type of file."
End If
End Sub
VC6.0 中 添加/取消 块注释的Macro代码的更多相关文章
- VC6.0中添加库文件和头文件
附加头文件包含 VC6.0中: VC6.0默认include包含路径:Tools>Options>Directories>Include files. 对于特定项目的头文件包含,在“ ...
- 在VC6.0中能不能使用Duilib界面库呢?
Duilib库的源代码是在vs2010下编译的,一般适用于vs2008及以上的版本开发使用,那么duilib能不能在vc6.0的工程中使用呢?如何在vc6.0中使用duilib库呢? 今天,由于工作要 ...
- [转贴]从零开始学C++之STL(二):实现一个简单容器模板类Vec(模仿VC6.0 中 vector 的实现、vector 的容量capacity 增长问题)
首先,vector 在VC 2008 中的实现比较复杂,虽然vector 的声明跟VC6.0 是一致的,如下: C++ Code 1 2 template < class _Ty, cl ...
- VC++ 6.0中添加库文件和头文件
附加头文件包含 VC6.0中: VC6.0默认include包含路径:Tools>Options>Directories>Include files. 对于特定项目的头文件包含,在& ...
- Notepad++怎么增加整行删除快捷键?添加/取消区块注释?
1.有网友说 Notepad++ 自带删除行功能,用快捷键 Ctrl+L 就可以删除一行.的确,这个快捷键是可以删除一行文本,但确切的说,Ctrl+L 并不是仅仅删除了一行文本,而是 剪切 了一行文本 ...
- VC 6.0中添加库文件和头文件 【转】
本文转载自:http://blog.sina.com.cn/s/blog_9d3971af0102wxjq.html 加头文件包含 VC6.0中: VC6.0默认include包含路径:Tools&g ...
- VC6.0中友元函数无法访问类私有成员的解决办法
举个例子: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #inclu ...
- [置顶] c++,vc6.0,中友元函数,无法访问私有字段(private)的问题(problem),cannot access private member declared in class 'Date'
c++,vc6.0,中友元函数,无法访问私有字段(private)的问题(problem),cannot access private member declared in class 'Date' ...
- Service 中添加同步块防止并发 重复
Service 中添加同步块防止并发 重复. synchronized(this){}
随机推荐
- 关于NHibernate的一些代码
SessionManager using System; using System.IO; using System.Runtime.Serialization; using System.Runti ...
- Oracle合并某一列
本文转载自:https://www.cnblogs.com/LeiYang5237/p/6761183.html 一.oracle11g使用listagg() within group()函数 如图一 ...
- k8s1.4.3安装实践记录(3)下载基础镜像
下载基础镜像,因为Google被墙,所以我们用时速云中的镜像来tag docker pull index.tenxcloud.com/google_containers/pause-amd64:3.0 ...
- Java-Runoob-高级教程:Java 数据结构
ylbtech-Java-Runoob-高级教程:Java 数据结构 1.返回顶部 1. Java 数据结构 Java工具包提供了强大的数据结构.在Java中的数据结构主要包括以下几种接口和类: 枚举 ...
- POJ-2282题解&数位DP总结
一.题意 给定一个区间[a, b](注意输入的时候可能a > b,所以,在数据输入后,要先比较a和b,如果a > b,交换a和b的值),统计这个区间里面,数位上有多少个0.多少个1.--. ...
- SSH框架的简化(struts2、spring4、hibernate5)
目的: 通过对ssh框架有了基础性的学习,本文主要是使用注解的方式来简化ssh框架的代码编写. 注意事项: 1.本文提纲:本文通过一个新闻管理系统的实例来简化ssh框架的代码编写,功能包括查询数据库中 ...
- PHP RSA加密解密
1.生成密钥和公钥 开始前需要准备openssl环境 linux 需要安装openssl工具包,传送门http://www.openssl.org/source/ window 下需要安装openss ...
- ubuntu 解决“无法获得锁 /var/lib/dpkg/lock -open”的方法
在ubuntu系统终端下,用apt-get install 安装软件的时候,如果在未完成下载的情况下将终端中断,此时 apt-get进程可能没有结束.结果,如果再次运行apt-get instal ...
- linux 远程连接服务器ftp命令整理
Ftp命令的功能是在本地机和远程机之间传送文件.该命令的一般格式如下: $ ftp 主机名/IP ftp将给出提示符,等待用户输入命令: $ ftp ftp > 最常用的命令有: ls 列出远程 ...
- 【开发工具】Jenkins+Gitlab实现自动化部署
我在尝试在容器中安装Jenkins时,初衷是希望使用docker in docker 的模式来实现Jenkins slave容器按需创建.在实现的时候需要在Jenkins 中安装Kubernetes插 ...