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){}
随机推荐
- 可复用的自定义Adapter
public abstract class MyAdapter<T> extends BaseAdapter { private ArrayList<T> mData; pri ...
- TMS320CC657基本外围电路调试
一.本文内容 本文主要包含以下三个基本外围电路的调试过程与调试结果: 电源模块 时钟模块 复位模块 二.电源模块调试 无论对FPGA还是DSP而言,对电源的上电顺序都有一定的要求,且不同型号的器件对电 ...
- Java中的强制类型转换
例如,当程序中需要将 double 型变量的值赋给一个 int 型变量,该如何实现呢? 显然,这种转换是不会自动进行的!因为 int 型的存储范围比 double 型的小.此时就需要通过强制类型转换来 ...
- ping第一包时间过长
一.现象 公司互联网域(说白了就是可以连外网的vlan区域的主机)的几台主机在ping一个合作方提供的域名时,发现在ping 第一个包时,时间特别长,后面第2--N包开始正常.直接ping 该域名对应 ...
- Nmon、nmon analyse安装及使用
性能监控算是性能测试中的一部分,测试人员需要去分析各类系统指标,CPU.网络.内存.磁盘I/O等等.嗯.通常linux系统下有诸如top.netstat.iostat等命令进行查看:而有时需要看某数据 ...
- oracke创建db link
-- Create database link create public database link test_link connect to 用户名 identified by 密码 using ...
- js控制手机震动
js控制手机震动 <button onclick="vibrate()">震动</button> <script> function vibra ...
- 由于安装Android设备驱动异常,ADB无法识别安卓设备的解决方案
体验更优排版请移步原文:http://blog.kwin.wang/programming/android-driver-exception-solution.html 最近换了台新电脑,在Andro ...
- Windows下安装kibana
1. 下载ElasticSearch https://www.elastic.co/downloads/kibana https://www.elastic.co/downloads/past-rel ...
- dart 命名规范
1.类型 首字母大写 譬如 abstract class Shape 2.变量 驼峰式命名,首字母小写 class Article { String headUrl; String user; Str ...