Debug VBScript with Visual Studio

http://blog.theopensourceu.com/2009/05/debug-vbscript-with-visual-studio/

For a project that I work on at at my primary employer, we use VBScript inside of DTS packages. Until this project, I’ve not had too much experience with VBScript. What I’ve found most frustrating about the language is the inability to step though the code… until a recent discovery. I’ve found that if I save the target code to my local machine as a VBS file and execute it with WScript.exe, I can attach a debugger to it.

I’ve discovered this by poking around and I don’t know too much about WScript.exe. I’m sure if you Google it, you can find more about it.

For this to work, you’ll need a copy of Visual Studio installed. I am not sure if any of the express editions will work. Drop a line in the comments if you find it will. As a quick walk though:

  1. Save your code as a VBS file. Don’t forget to call Main (or your main) function as wscript won’t automatically call main.
  2. Open a command prompt.
  3. Navigate to the location of the file.
  4. Type: WScript.exe FileName.vbs //D //X
  5. You should be prompted to select a debugger, select a new instance of either Visual Studio 2003, 2005 or 2008.
  6. Visual studio will open up and break at the very first line.
  7. Step though the code.

For an example, save the following as “Example.vbs” on your desktop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
MsgBox "Starting Script!"
Dim i : i = 0
Const C_Max = 100
Dim sPrimeNumberList : sPrimeNumberList = "Prime Numbers: " & vbCrLf
For i = 0 to C_Max
  If IsNumberPrimeNumber(i) Then
     sPrimeNumberList = sPrimeNumberList & cStr (i) & ", "
  End If
Next
MsgBox sPrimeNumberList
MsgBox "Script Completed."

Public Function IsNumberPrimeNumber( ByVal iNumber)
Dim bIsPrime : bIsPrime = True
For j = 2 To iNumber/2
  bIsPrime = iNumber Mod j > 0
  If Not bIsPrime Then Exit For
Next
IsNumberPrimeNumber = bIsPrime
End Function

Open a command prompt and navigate to your desktop:

Command Prompt for Debugging VBScript from Visual Studio

Command Prompt for Debugging VBScript from Visual Studio

Once there, type in the following:

1
 wscript Example.vbs // D // X

You should then be presented with a dialog similar to the following:

Visual Studio Debugging VBScript

Visual Studio Debugging VBScript

Once you make a selection, you should get something like the following:

Debugging VBScript from Visual Studio

Debugging VBScript from Visual Studio

From here, I’ll assume you are familiar enough with Visual Studio to play with the debugger and learn how it works. When debugging VBScript, I’ve found that you don’t have all the options that you might be used to such as Step In To, but for me simply having this much is a life saver.

To get around the step-in-to thing , I simply use Run to Cursor . It works like a charm.

Update: I just found that (at least on this computer) and in Visual Studio 2003, I have all my standard code-stepping buttons available. I’m not sure why on my work computer I only have Step-Over but either way, this is still a life saver.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!
Visual Studio Debug是指使用Visual Studio集成开发环境进行程序调试的过程。调试是开发过程中的重要环节,它可以帮助开发人员找出程序中的错误并进行修复。在Visual Studio中,可以使用多种调试工具和技术来辅助调试过程。 调试前,需要将解决方案配置设置为Debug模式,而不是Release模式。Debug模式生成的代码包含了调试信息,便于程序调试。而Release模式生成的代码则进行了性能优化,但不利于调试。 在Visual Studio中,可以使用跟踪点(Breakpoint)来在代码中设置断点,用于观察程序的执行状态。在调试过程中,可以通过跟踪点将信息记录到“输出”窗口中,以便进行调试信息的查看。可以使用快捷键Ctrl + Alt + B或通过Debug菜单中的Windows选项查看整个解决方案中的断点。 通过调试过程中的断点管理,开发人员可以了解断点在何处设置,以便更好地进行调试。在大型项目中,通常会有许多断点,因此合理的断点管理对于调试操作的效率非常重要。 总结来说,Visual Studio Debug是通过设置断点和使用调试工具来辅助程序调试的过程,可以帮助开发人员找出代码中的错误并进行修复。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [【教程】visual studio debug 技巧总结](https://blog.csdn.net/qq_34902437/article/details/126682065)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Visual Studio 调试系列1 Debug 与 Release 模式](https://blog.csdn.net/baibin7264/article/details/101089676)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值