How do I output code while debugging in Visual Basic 2010?

蓝咒 提交于 2019-12-07 16:28:52

问题


When I'm debugging my application something is not right, and I can't continue. So is it possible to see the output code of my app while I'm testing it to see what is wrong?

I open the output window but nothing happens in there it's just stay blank. In two words: I want to see what my app is actually doing while I'm testing it. I'm using Visual Studio 2010.


回答1:


So is it possible to see the output code of my app while im testing it to see what is wrong?

Yes, but you actually have to output something, otherwise nothing will show up. In VB.NET (which is the language you're using if you have Visual Studio 2010), this is accomplished with the following code:

Debug.Print("Here is some text that will be output.")

The documentation for the Debug.Print method is here. In order to call it like that, you will also have to have imported the System.Diagnostics namespace. You do so by placing the following line at the top of your code file (with all the other statements that look like it):

Imports System.Diagnostics

The output will automatically appear in the Output Window. If you still don't see anything, ensure that output is not being redirected to the Immediate Window instead: Tools -> Options -> Debugging -> General -> uncheck the option "Redirect all Output Window text to the Immediate Window".


Confusingly, you use the word "code" in your question, saying that you wish to "see the output code of [your] app while testing it". I'm not sure if by "code" you actually mean "output", in which case the solution above will work for you.

If you actually mean code, as in your program's source code, then you can use the Break toolbar button (or press Ctrl+Break) in the IDE to pause the execution of your program. This will automatically dump you back into the code editor with the currently-executing line of code highlighted.

Visual Studio has some very powerful debugging tools. If you don't already have a general idea of how to use them, I strongly recommend picking up a book on either it or VB 2010 that will teach these things to you. They can be very confusing to learn by trial and error, but are not all that difficult if you have a good guide. Spend that time debugging your code, not figuring out how to use the IDE.



来源:https://stackoverflow.com/questions/15490228/how-do-i-output-code-while-debugging-in-visual-basic-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!