vb.net 在 Visual Basic 2010 中调试时如何输出代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15490228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 16:45:45  来源:igfitidea点击:

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

vb.netvisual-studiodebuggingoutput

提问by Plamen Provenzano

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.

我打开输出窗口,但那里什么也没发生,它只是保持空白。简而言之:我想看看我的应用程序在测试时实际在做什么。我正在使用 Visual Studio 2010。

回答by Cody Gray

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 outputsomething, 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:

是的,但你实际上必须输出一些东西,否则什么都不会显示。在 VB.NET(如果您有 Visual Studio 2010 时使用的语言),这是通过以下代码完成的:

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

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

Debug.Print方法的文档在此处。为了这样调用它,您还必须导入System.Diagnostics命名空间。为此,您可以将以下行放在代码文件的顶部(以及所有其他类似的语句):

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.

如果您的意思是code,就像在程序的源代码中一样,那么您可以使用IDE 中的 Break 工具栏按钮(或按Ctrl+ Break)来暂停程序的执行。这将自动将您转回代码编辑器,并突出显示当前正在执行的代码行。

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.

Visual Studio 有一些非常强大的调试工具。如果您对如何使用它们还没有一个大致的概念,我强烈建议您拿起一本关于它或 VB 2010 的书来教您这些东西。通过反复试验来学习它们可能会非常令人困惑,但如果您有一个好的指南,它们就不会那么困难。花时间调试您的代码,而不是弄清楚如何使用 IDE。