I keep getting an error message and do not know how to fix it!!

  • Thread starter Thread starter Joshua Cruz 16
  • Start date Start date
J

Joshua Cruz 16

Guest
Hello! I am coding a program which takes 3 grades you enter into a simple form, and when you click the buttons it averages out your grade and gives a letter grade... But when i click on "Calculate Average" i get an error saying "Value of type 'Double' cannot be converted to 'Textbox'

Here is my code


'Name: Joshua Cruz
'Date: 10/29/18

Option Strict On



Public Class Form1

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'This event closes the form.
Close()
End Sub
''
Private Sub btnAvg_Click(sender As Object, e As EventArgs) Handles btnAvg.Click
'Declare each variable
Dim grade As String
Dim grade2 As String
Dim grade3 As String

'Assigning variables
grade = CType(CInt(txt1.Text), String)
grade2 = CType(CInt(txt2.Text), String)
grade3 = CType(CInt(txt3.Text), String)


' THIS CHECKS IF ANYTHING IS TYPED INTO THE GRADE BOXES
If txt1.Text = "" Then
MsgBox("ENTER A NUMBER")
ElseIf txt2.Text = "" Then
MsgBox("ENTER A NUMBER IN TEST 2")
ElseIf txt3.text = "" Then
MsgBox("ENTER A NUMBER IN TEST 3")
End If

'Simple adding and dividing to equal average

txtAverage = CInt((grade + grade2 + grade3)) / 3

If CInt(grade) > 100 Then
MsgBox("TEST 1 IS GREATER THAN 100 CHECK!")
ElseIf CInt(grade) < 0 Then
MsgBox("TEST 1 IS LESS THAN 0!")
ElseIf CInt(grade2) > 100 Then
MsgBox("Test 2 IS GREATER THAN 100! CHECK!")
ElseIf CInt(grade2) < 0 Then
MsgBox("Test 2 IS LESS THAN 0! CHECK!")
ElseIf CInt(grade3) > 100 Then
MsgBox("Test 3 IS GREATER THAN 100! CHECK!")
ElseIf CInt(grade3) < 0 Then
MsgBox("Test 3 IS LESS THAN 0! CHECK!")
End If
End Sub

Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
'Declare variables
Dim letter As String
Dim score As String
score = txtAverage.Text
letter = txtGrade.Text
' CHECKS IF A GRADE IS CALCULATED
If txt1.Text = "" Then
MsgBox("Make sure all grades are entered!")
ElseIf txt2.Text = "" Then
MsgBox("Check test 2!")
ElseIf txt3.Text = "" Then
MsgBox("Check test 3!")
End If
'Nested if which determines your average and converts into a letter grade.
If CInt(score) >= 90 And CInt(score) <= 100 Then
letter = "A"
ElseIf CInt(score) >= 80 And CInt(score) < 90 Then
letter = "B"
ElseIf CInt(score) >= 70 And CInt(score) < 80 Then
letter = "C"
ElseIf CInt(score) >= 60 And CInt(score) < 70 Then
letter = "D"
Else
letter = "F"
End If
'Wont print out into grade box
txtGrade.Text = letter
End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txt1.Clear()
txt2.Clear()
txt3.Clear()
txtAverage.Clear()
txtGrade.Clear()
txt1.Focus()
End Sub
End Class

Continue reading...
 
Back
Top