您的位置:首页 > 编程语言

代码格式化脚本CodeFormat

2004-02-05 18:29 495 查看
没学过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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  脚本 c++ each c