In practical work, I find that the most common complaint that programmers have about scripts is that scripts are difficult to debug, especially when debugging. VBS and other WSH programs, they always:
1. Double click a. VBS file in the resource manager.
2. An error occurs in the program, such as an exception, or a programming logic error.
3. Read the source file line by line, then add a lot of msgbox.show and print the values of some variables where the estimation is wrong.
4. Re execute. VBS file
5. “Dangdang”, after a series of “confirm” points, people are dizzy, and go back to the third step to continue
In fact, we can also use visual studio to debug such WSH programs. The key is that wscript.exe and cscript.exe, the interpreters of WSH script programs such as. VBS, provide debugging support:
1. When we double-click a. VBS file in the resource manager, the resource manager actually runs wscript.exe to interpret and execute the. VBS file.
2. Both wscript.exe and cscript.exe support these two options / D – enable debugging function, / X – execute script program in debugger.
In this way, we can use two methods to debug script programs in visual studio. Here I only introduce the second method — the first method does not know why my win 7 + Visual Studio 2008 cannot work,: (.
For example, the following. VBS code is saved to C: “test.vbs. We want to debug this program. The source file is as follows:
obj.Add(“this is a test”)
1. Open the command line, change the directory to the C: disk, and execute the following command:
Wscript.exe /X test.vbs
2. At this time, a visual studio dialog box should pop up to prompt you to select the appropriate debugger and click the OK button above.
3. Finally, you can set breakpoints in visual studio and view the values of variables just like debugging C ා or C + + programs, as shown in the following figure: