VS2005实用宏

前端之家收集整理的这篇文章主要介绍了VS2005实用宏前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

现在的IDE越做越强大,为我等懒人省了不少。为了使用将来的代码自己或别人能看懂,注释这种东西必不可少。当为函数添加注释时,格式是固定的。每个函数写一遍,或从别的函数处拷贝过来,即麻烦又容易出错。这种重复劳动让人心烦都有不想写注释的欲望了,这时VS的宏可以干掉这些“脏、乱、累”的体力活。

看了一下,VS2005的宏脚本就是VBScript,很容易上手。我写了一个生成函数注释模板的宏脚本,比较容易,看代码

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  1. '为函数自动添加注释
  2. 'Script By Lonkil www.vcfans.com
  3. Sub AddFunComment()
  4. Dim DocSel As EnvDTE.TextSelection
  5. DocSel = DTE.ActiveDocument.Selection
  6. DocSel.NewLine()
  7. DocSel.Text = "/*******************************************************************"
  8. DocSel.NewLine()
  9. DocSel.Text = "* 函数名称: "
  10. DocSel.NewLine()
  11. DocSel.Text = "* 功 能: "
  12. DocSel.NewLine()
  13. DocSel.Text = "* 参 数: "
  14. DocSel.NewLine()
  15. DocSel.Text = "* 返 回 值: "
  16. DocSel.NewLine()
  17. DocSel.Text = "* 作 者: Lonkil"
  18. DocSel.NewLine()
  19. DocSel.Text = "* 电子邮箱: lonkil{AT}gmail.com ( {AT} -> @ )"
  20. DocSel.NewLine()
  21. DocSel.Text = "* 创建日期: " + System.DateTime.Now.ToLongDateString()
  22. DocSel.NewLine()
  23. DocSel.Text = "*******************************************************************/"
  24. End Sub

具体的创建步骤:VS2005 IDE -> 工具 -> 宏 -> 新建宏项目,选择要保存的位置。然后将要上面的脚本复制进去,保存即可。

具体的使用:为你编写的宏绑定快捷键,VS2005 IDE -> 工具 -> 选项 -> 在左边列表中选择“键盘” -> 在右边的“显示命令包含”中,选择你创建宏-> 将光标定位到”按快捷键”处 -> 输入你想命名的快捷键,比如”Alt+C”,保存即可。

有一点需要注意:Visual Studio 2005 Team Suite 需要打上SP1补丁,宏方能使用否则无效。

转自http://www.vcfans.com/2008/09/vs2005-macro-script-template-add-comments.html

猜你在找的VB相关文章