I need help with this problem in Visual Basic 2012: * I am not allowed to use ar
ID: 3670169 • Letter: I
Question
I need help with this problem in Visual Basic 2012: *I am not allowed to use arrays or loops*
"Write a program that reads a test score from a text box each time a button is clicked and then displays the two highest scores whenever a second button is clicked. Use two class-level variables to track the two highest scores."
Here is my code so far. I keep getting an error that the double to string conversion is invalid. I am not sure if that if statement is what I need. Also, the me.refresh is not what I need. How do I restart the code without restarting the program?
Option Strict On
Public Class FrmHighestScores
Dim high1 As Double = 0
Dim high2 As Double = 0
Private Sub BtnCurrentScore_Click(sender As Object, e As EventArgs) Handles BtnCurrentScore.Click
TxtScore.Clear()
End Sub
Private Sub BtnTwoHighest_Click(sender As Object, e As EventArgs) Handles BtnTwoHighest.Click
Dim score As Double = CDbl(TxtScore.Text)
score += 1
score = high1
If score > high1 Then
score = high2
End If
TxtHighest.Text = CStr(high1 & " , " & high2)
End Sub
Private Sub BtnRestart_Click(sender As Object, e As EventArgs) Handles BtnRestart.Click
Me.Refresh()
TxtHighest.Clear()
End Sub
Private Sub BtnQuit_Click(sender As Object, e As EventArgs) Handles BtnQuit.Click
End
End Sub
End Class
Explanation / Answer
Use the following way to convert the user input text into a Double value :
This logic above will help you to get rid off the double to string conversion cast error.