0

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.

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.

1
  • The ONLY thing I miss about VB6 is the Immediate Window. You could create objects and run lines like this really easily. Commented Sep 29, 2010 at 20:52

3 Answers 3

2

You could extract this into a method, that takes the values needed as parameters, then create a test harness to execute it.

Sign up to request clarification or add additional context in comments.

Comments

1


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)
Open it and type:
CorrectAnswers=25.5
TotalQuestions=30
?Math.Round((Math.Abs(CorrectAnswers) / TotalQuestions) * 100)
And you'll get:
85.0 {Double}
Double: 85.0
Tip: type >cls to clear the immediate window contents.
I don't understand how Bill says he misses it from VB6. We have it too at VisualStudio and fully functional :)
Regards.
ps:I translate from the spanish 2008 version so you could have other menu options, hotkeys, etc.

1 Comment

Thank you for the answer I will have to try this out today.
0

So there are 150 questions, and they can either be right or wrong? Which means there are only 151 possible inputs? 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. 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. You can change this behaviour.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.