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){}
随机推荐
- 队列之blah集合
做了一个NOI上面的问题,叫blah集合,以a为基数,则2x+1和3x+1都在集合中,且集合中全部元素都由此计算得来.a∈[1,50],问升序排列后第n(n∈[1,1000000])个元素是多少.以输 ...
- FC Switch sfpshow
sfpshow - fault-finding on Brocade Fibre Channel Switches So you've hit a situation where a Fibre Ch ...
- python--logging库学习_自我总结---有空完善
思路: 1.把前面的都封装,然后在测试用例里面调用,每一步测试步骤下面都加一个 logging.info('这个是测试步骤')(可以 亲测) 2.尝试添加到unittest框架里面,看能不能一起使用 ...
- docker 远程rest api 访问配置
Docker RestApi 的配置及使用 Centos Docker1.12 远程Rest api访问的配置方法 http restapiv1.24 docker sdk for python
- mysql内置函数,在mysql里面利用str_to_date()把字符串转换为日期格式
mysql内置函数,在mysql里面利用str_to_date()把字符串转换为日期格式 示例:分隔符一致,年月日要用%号 select str_to_date('2008-4-2 15:3:28', ...
- django-cbv模式-csrf中间件
1. django模式 def users(request): user_list = ['alex','oldboy'] return HttpResponse(json.dumps((user_l ...
- 表格字段常用注解@NotBlank @NotEmpty @NotNul @Pattern
在Hibernate Validator(org.hibernate.validator.constraints)中: @NotEmpty://CharSequence, Collection, Ma ...
- 分享Axure RP8.0激活码一份
用户名:aaa 注册码:2GQrt5XHYY7SBK/4b22Gm4Dh8alaR0/0k3gEN5h7FkVPIn8oG3uphlOeytIajxGU
- redis rdb文件解析
http://www.ttlsa.com/python/redis-rdb-tools-analysis-of-reids-dump-file-and-memory-usage/ redis-rdb- ...
- XSD 学习
1.新建文件 Rhythmk.xsd <?xml version="1.0" encoding="utf-8"?> <xs:schema id ...