In practice, I find that programmers complain most about scripting that it is difficult to debug this shortcoming, especially when debugging. VBS and other WSH programs, always:
1. In the Resource Manager, double-click A. vbs file.
2. An error occurred in the program, such as an exception, or a programming logic error.
3. Read the source file in one line, then add a lot of msgbox.show and print the values of some variables where the error is estimated to occur.
4. Re-executing the. vbs file
5. "When", a series of "OK" after the point is over, people are dizzy, back to the third step to continue ...
In fact, we can also debug such WSH programs with Visual Studio, and the key is to provide debugging support for the interpreter Wscript.exe and cscript.exe of WSH scripts such as. vbs:
1. When we double-click a. vbs file in the Explorer, the resource manager actually runs wscript.exe to interpret and execute the. vbs file.
2. Both Wscript.exe and Cscript.exe support both options/d– enable debugging,/x– execute the script in the debugger.
So, there are two ways to debug a script in Visual Studio, and I'll just introduce the second method--the first method doesn't know why my win 7 + Visual Studio 2008 doesn't work,:(.
For example, the following. vbs code, save it to C: "Test.vbs, we want to debug this program, the source file is as follows:
Copy Code code as follows:
Set obj = CreateObject ("System.Collections.ArrayList")
Obj. ADD ("This is a test")
Obj. ADD (1)
Obj. ADD (obj)
Msgbox obj (0)
Msgbox obj (1)
Msgbox obj (2). ToString ()
1. Open the command line, replace the directory to C: Disk, execute the following command:
wscript.exe/x Test.vbs
2. This time, you should pop up a Visual Studio dialog box that prompts you to select the appropriate debugger and click on the OK button above.
3. Finally, you can set breakpoints in Visual Studio, like debugging C # or C + + programs, to view the values of variables, as shown in the following illustration: