简体   繁体   English

是否可以在不运行项目的情况下使用vs2010执行vb.net代码?

[英]Is it possible to execute vb.net code using vs2010 without running the project?

This may be a strange question and have no answer but I thought I would post it to see how you would go about doing it. 这可能是一个奇怪的问题,没有答案,但我想我会发布它,看看您将如何去做。 I have a line of code: 我有一行代码:

Grade = Math.Round((Math.Abs(CorrectAnswers) / TotalQuestions) * 100)

Basically that line just figures out the grade no major code work there, what I want to do is execute that specific line with different variables without running the whole application and navigating to the point in the application which for this segment would be completing a 150 question exam, or coding some #temp page and running it from there. 基本上那条线只是弄清楚年级,那里没有主要的代码工作,我想做的是用不同的变量执行那条特定的线,而无需运行整个应用程序并导航到应用程序中要针对这一部分完成150个问题的要点考试,或编写一些#temp页面并从那里运行它。

I am trying to track a bug in the code that happens very rarely (you know when the planets in the universe are out of cosmic alignment) and I think my issue lies with this subset and I am trying to find a better/easier way of testing it. 我试图跟踪代码中很少发生的错误(您知道何时宇宙中的行星不符合宇宙定线),我认为我的问题出在这个子集上,我试图找到一种更好/更容易的方式测试它。

您可以将其提取到一个方法中,该方法将所需的值用作参数,然后创建一个测试工具来执行它。


If you add a Class Diagram item to the project and from Solution Explorer you drag the class file which contains the method into it, you can invoke static methods (right click on the Class element or use Class Diagram Menu). 如果将类图项目添加到项目中,然后从解决方案资源管理器中将包含该方法的类文件拖到项目中,则可以调用静态方法(右键单击类元素​​或使用类图菜单)。
It will ask you the values for the arguments. 它将询问您参数的值。

And really you do can use Immediate window (Ctrl+G or Debug->Windows menu) 确实可以使用即时窗口(Ctrl + G或Debug-> Windows菜单)
Open it and type: 打开它并输入:
CorrectAnswers=25.5 CorrectAnswers = 25.5
TotalQuestions=30 TotalQuestions = 30
?Math.Round((Math.Abs(CorrectAnswers) / TotalQuestions) * 100) Math.Round((Math.Abs​​(CorrectAnswers)/ TotalQuestions)* 100)
And you'll get: 您会得到:
85.0 {Double} 85.0 {双}
Double: 85.0 双:85.0
Tip: type >cls to clear the immediate window contents. 提示:键入> cls以清除即时窗口内容。
I don't understand how Bill says he misses it from VB6. 我不明白比尔说他如何错过VB6。 We have it too at VisualStudio and fully functional :) 我们在VisualStudio中也有它,并且功能齐全:)
Regards. 问候。
ps:I translate from the spanish 2008 version so you could have other menu options, hotkeys, etc. ps:我从西班牙语2008版本翻译而来,因此您可以使用其他菜单选项,热键等。

So there are 150 questions, and they can either be right or wrong? 因此,有150个问题,它们是对还是错? Which means there are only 151 possible inputs? 这意味着只有151种可能的输入? Why not just calculate them all? 为什么不仅仅计算它们呢? Run this in a console application and see whether you like the results. 在控制台应用程序中运行此命令,然后查看是否喜欢结果。

  Sub Main()
    Dim Grade As Integer
    Const TotalQuestions = 150
    Console.WriteLine("Marks             Grade")
    For CorrectAnswers = 0 To 150
      Grade = Math.Round((Math.Abs(CorrectAnswers) / TotalQuestions) * 100)
      Console.WriteLine(Format(CorrectAnswers, "000") & " out of 150 => " & _
                         Format(Grade, "000"))
    Next CorrectAnswers
    Console.ReadLine()
  End Sub

Be aware that Math.Round uses banker's rounding by default. 请注意,Math.Round默认使用银行家的舍入 If the fractional component of a is halfway between two integers, one of which is even and the other odd, then the even number is returned. 如果a的小数部分位于两个整数之间的中间,其中一个为偶数,另一个为奇数,则返回偶数。 You can change this behaviour . 您可以更改此行为

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM