代码格式化脚本CodeFormat

王朝vc·作者佚名  2006-01-08
宽屏版  字体: |||超大  

没学过VBSript,但为了格式化自己要用的代码,找来找去没找到合适的,勉强作了一个。用法:将下面代码存成一个“.DSM”后缀的文件,用VC6装载这个宏,打开任一C,C++代码文件,运行宏,代码将按系统设置的方式(空格或TAB)得到格式化。由于不懂VBSript,做得不完善,问题是:1:必须把欲格式化的文件在VC等环境下打开,不能按目录自动检索该格式化的文件;2:在“{”后有字符时{}里面的失去缩进;

条件:文件必须可写。

存在的价值:VC环境是大家信任的环境,绝不会因为它对代码格式化而使代码不能编译。

希望有人不吝技术,把它做好一点。如果有新版,请寄给我一份:Yanggr@cbcyber.com

Sub FormatByCode()

Dim myDocument

For Each myDocument in Application.Documents

myDocument.Active = True

myDocument.Selection.SelectAll

Dim EndLine, CurrLine

EndLine=myDocument.Selection.BottomLine

myDocument.Selection.StartOfLine

CurrLine=myDocument.Selection.CurrentLine

while ( CurrLine<=EndLine )

myDocument.Selection.SelectLine

myDocument.Selection = LTrim(myDocument.Selection)

CurrLine=myDocument.Selection.CurrentLine

wend

myDocument.Selection.SelectAll

myDocument.Selection.Unindent

myDocument.Selection.Unindent

myDocument.Selection.Unindent

myDocument.Selection.Unindent

myDocument.Selection.Unindent

myDocument.Selection.Unindent

myDocument.Selection.SmartFormat

myDocument.Save

myDocument.Close dsSaveChangesPrompt

Next

End Sub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有