代码格式化脚本CodeFormat

没学过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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值