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

  • Question

  • 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

    Thursday, November 1, 2018 1:44 PM

Answers

  • Hi

    First of all. Please post code in a Code Block (from the toolbar)

    Secondly, presumably the exception was at a particular line (although there are many possibilities to choose from) - you should include the line(s) where exceptions are occurring.

    *

    The particular exception you mention Value of type 'Double' cannot be converted to Textbox - is possibly because you forgot to say 'TextBox1.Text =' the exception telling you that a TextBox cannot be the target of an assignment of a Double.

    *

    A quick look through your code suggests that you are not quite familiar with the use of different Types.

    When you need to use Strings in calculations, you MUST convert them to a numeric Type, such as Integer, Double or Decimal etc according to your needs before you try to do any calculation with them.

    I also see that you go to great lengths to convert a String variable to an Integer and then back to a String all on the same line. This is not achieving anything. eg

    Dim grade As String
    
    grade = CType(CInt(txt1.Text), String)

    where 'grade' is already defined as a String, so,

    Dim grade As String
    grade = txt1.Text

    would do the same (although, you could even do without that line)

    You then procede to try and add variables using 'grade' which is a String.

    I wonder if what you truly want is something like this:

    Dim grade As Integer
    grade = CInt(txt1.Text)


    Regards Les, Livingston, Scotland


    • Edited by leshay Thursday, November 1, 2018 2:38 PM
    • Marked as answer by Joshua Cruz 16 Friday, November 2, 2018 9:48 PM
    Thursday, November 1, 2018 2:36 PM

  • Is there an easier way? In my course we have yet to learn what those extra commands do in VB. My teacher expects us to explain the code we right also

    While we wait for you to post the *current* code that you are working with
    so we can see if there's any issues with it, let's take a look back at the
    original code you posted. The following is a breakdown of what was happening
    in this line:

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

    Here you are concatenating the three strings and then converting the 
    resulting string to an Int. You are then dividing the sum by 3 using
    the / operator which returns a double. This is probably where the
    reference to a double came from in your error message.

    Consider this example:

    Dim grade As String = "64"
    Dim grade2 As String = "70"
    Dim grade3 As String = "82"
    
    ' This combines the three strings to get "647082" 
    ' which is then converted to an Int32
    Dim txtAverage As Int32 = CInt((grade + grade2 + grade3)) \ 3 ' = 215694
    
    ' This converts each of the three strings to integers 
    ' and then adds the three integers
    Dim txtAverage2 As Int32 = (CInt(grade) + CInt(grade2) + CInt(grade3)) \ 3 ' = 72
    
    ' Note the use of the \ operator instead of the / operator
    ' Operator \ returns an integer quotient
    ' Operator / returns a double quotient plus remainder
    
    

    References:

    \ Operator (Visual Basic)
    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/integer-division-operator

    / Operator (Visual Basic)
    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/floating-point-division-operator

    - Wayne

    • Marked as answer by Joshua Cruz 16 Sunday, November 4, 2018 12:41 AM
    Sunday, November 4, 2018 12:39 AM

  • Is there an easier way? In my course we have yet to learn what those extra commands do in VB. My teacher expects us to explain the code we right also

    While we wait for you to post the *current* code that you are working with
    so we can see if there's any issues with it, let's take a look back at the
    original code you posted. The following is a breakdown of what was happening
    in this line:

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

    Here you are concatenating the three strings and then converting the 
    resulting string to an Int. You are then dividing the sum by 3 using
    the / operator which returns a double. This is probably where the
    reference to a double came from in your error message.

    Consider this example:

    Dim grade As String = "64"
    Dim grade2 As String = "70"
    Dim grade3 As String = "82"
    
    ' This combines the three strings to get "647082" 
    ' which is then converted to an Int32
    Dim txtAverage As Int32 = CInt((grade + grade2 + grade3)) \ 3 ' = 215694
    
    ' This converts each of the three strings to integers 
    ' and then adds the three integers
    Dim txtAverage2 As Int32 = (CInt(grade) + CInt(grade2) + CInt(grade3)) \ 3 ' = 72
    
    ' Note the use of the \ operator instead of the / operator
    ' Operator \ returns an integer quotient
    ' Operator / returns a double quotient plus remainder
    
    

    References:

    \ Operator (Visual Basic)



    - Wayne

    '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 = txt1.Text
            grade2 = txt2.Text
            grade3 = txt3.Text
      ***      txtAverage.Text = CInt((grade + grade2 + grade3)) / 3        ***
    
            ' 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
    
            If grade > 100 Then
                MsgBox("TEST 1 IS GREATER THAN 100 CHECK!")
            ElseIf grade < 0 Then
                MsgBox("TEST 1 IS LESS THAN 0!")
            ElseIf 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")
            ElseIf grade2 > 100 Then
                MsgBox("Test 2 IS GREATER THAN 100! CHECK!")
            ElseIf grade2 < 0 Then
                MsgBox("Test 2 IS LESS THAN 0! CHECK!")
            ElseIf grade3 > 100 Then
                MsgBox("Test 3 IS GREATER THAN 100! CHECK!")
            ElseIf 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
    
      
        End Sub
    End Class
    
    When i click btnAverage the number isnt being averaged out its just printing whole numbers... EG-"10+10= 1010"
    I put stars where i need help... I learned turning option strict on deems numbers must equal numbers but when its flicked on i just get a whole bunch of error messages...  i tired adding "+" into the equation another thing we learned and nothing is working
    • Marked as answer by Joshua Cruz 16 Sunday, November 4, 2018 10:53 PM
    Sunday, November 4, 2018 12:59 AM

All replies

  • I have not gone over everything but the following stick out.

    This is wrong.

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

    grade, grade2 and grade3 are strings. What I suggest is.

    • Use Integer.TryParse on all three strings, make sure that can be converted.
    • If all are integers then perform the average into a integer variable, assign the variable to the TextBox using .ToString on the variable storing the average.

    This is super funky, grades should be integers as per above. Use TryParse.

    grade = CType(CInt(txt1.Text), String)

    Example

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If Not String.IsNullOrWhiteSpace(TextBox1.Text) Then
                Dim value As Integer = 0
                If Integer.TryParse(TextBox1.Text, value) Then
                    ' value is good to go
                Else
                    ' value is not a valid integer
                End If
            Else
                ' nothing to do
            End If
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 1, 2018 2:20 PM
    Moderator
  • I have not gone over everything but the following stick out.

    This is wrong.

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

    grade, grade2 and grade3 are strings. What I suggest is.

    • Use Integer.TryParse on all three strings, make sure that can be converted.
    • If all are integers then perform the average into a integer variable, assign the variable to the TextBox using .ToString on the variable storing the average.

    This is super funky, grades should be integers as per above. Use TryParse.

    grade = CType(CInt(txt1.Text), String)

    Example

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If Not String.IsNullOrWhiteSpace(TextBox1.Text) Then
                Dim value As Integer = 0
                If Integer.TryParse(TextBox1.Text, value) Then
                    ' value is good to go
                Else
                    ' value is not a valid integer
                End If
            Else
                ' nothing to do
            End If
        End Sub
    End Class


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    Is there an easier way? In my course we have yet to learn what those extra commands do in VB. My teacher expects us to explain the code we right also
    Thursday, November 1, 2018 2:25 PM
  • Is there an easier way?

    all u hav 2 du magnifyglass error 2 find exam + poles using cstr

    less you jus cus me again maybe dat wil hep

    :)

    btw that mean joke son

    Thursday, November 1, 2018 2:31 PM
  •  when i click on "Calculate Average" i get an error saying "Value of type 'Double' cannot be converted to 'Textbox'


    Show the *exact* error message and details. Don't paraphrase it or abbreviate
    it. If possible post a screen capture of the error rather than trying to 
    type it in. Show the *exact* line in the code where the error occurs and 
    make it clear so we don't have to go searching for it.

    When posting code use the "Insert Code Block" button on the forum editor
    menu bar.

    I don't see any doubles in the code you posted.

    - Wayne

    Thursday, November 1, 2018 2:32 PM
  • Hi

    First of all. Please post code in a Code Block (from the toolbar)

    Secondly, presumably the exception was at a particular line (although there are many possibilities to choose from) - you should include the line(s) where exceptions are occurring.

    *

    The particular exception you mention Value of type 'Double' cannot be converted to Textbox - is possibly because you forgot to say 'TextBox1.Text =' the exception telling you that a TextBox cannot be the target of an assignment of a Double.

    *

    A quick look through your code suggests that you are not quite familiar with the use of different Types.

    When you need to use Strings in calculations, you MUST convert them to a numeric Type, such as Integer, Double or Decimal etc according to your needs before you try to do any calculation with them.

    I also see that you go to great lengths to convert a String variable to an Integer and then back to a String all on the same line. This is not achieving anything. eg

    Dim grade As String
    
    grade = CType(CInt(txt1.Text), String)

    where 'grade' is already defined as a String, so,

    Dim grade As String
    grade = txt1.Text

    would do the same (although, you could even do without that line)

    You then procede to try and add variables using 'grade' which is a String.

    I wonder if what you truly want is something like this:

    Dim grade As Integer
    grade = CInt(txt1.Text)


    Regards Les, Livingston, Scotland


    • Edited by leshay Thursday, November 1, 2018 2:38 PM
    • Marked as answer by Joshua Cruz 16 Friday, November 2, 2018 9:48 PM
    Thursday, November 1, 2018 2:36 PM
  • I have not gone over everything but the following stick out.

    This is wrong.

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

    grade, grade2 and grade3 are strings. What I suggest is.

    • Use Integer.TryParse on all three strings, make sure that can be converted.
    • If all are integers then perform the average into a integer variable, assign the variable to the TextBox using .ToString on the variable storing the average.

    This is super funky, grades should be integers as per above. Use TryParse.

    grade = CType(CInt(txt1.Text), String)

    Example

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If Not String.IsNullOrWhiteSpace(TextBox1.Text) Then
                Dim value As Integer = 0
                If Integer.TryParse(TextBox1.Text, value) Then
                    ' value is good to go
                Else
                    ' value is not a valid integer
                End If
            Else
                ' nothing to do
            End If
        End Sub
    End Class


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    Is there an easier way? In my course we have yet to learn what those extra commands do in VB. My teacher expects us to explain the code we right also

    Easier is not better in this case but as already pointed out you can use

    Dim Value As Integer = CInt(someTextBox.Text)

    In regards to explaining TryParse, programming is about learning and at times going past what the instructor has taught to a specific point in time. If you research TryParse you would get a page such as this one which explains in simple words about TryParse.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 1, 2018 2:42 PM
    Moderator
  • I have not gone over everything but the following stick out.

    This is wrong.

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

    grade, grade2 and grade3 are strings. What I suggest is.

    • Use Integer.TryParse on all three strings, make sure that can be converted.
    • If all are integers then perform the average into a integer variable, assign the variable to the TextBox using .ToString on the variable storing the average.

    This is super funky, grades should be integers as per above. Use TryParse.

    grade = CType(CInt(txt1.Text), String)

    Example

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If Not String.IsNullOrWhiteSpace(TextBox1.Text) Then
                Dim value As Integer = 0
                If Integer.TryParse(TextBox1.Text, value) Then
                    ' value is good to go
                Else
                    ' value is not a valid integer
                End If
            Else
                ' nothing to do
            End If
        End Sub
    End Class


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    Is there an easier way? In my course we have yet to learn what those extra commands do in VB. My teacher expects us to explain the code we right also

    Easier is not better in this case but as already pointed out you can use

    Dim Value As Integer = CInt(someTextBox.Text)

    In regards to explaining TryParse, programming is about learning and at times going past what the instructor has taught to a specific point in time. If you research TryParse you would get a page such as  which explains in simple words about TryParse.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.


    Thank you but now when I am trying to calculate the average under "Private Sub btnAvg_click", nothing is being displayed into the text box for average ("txtaverage.text")

    Friday, November 2, 2018 9:56 PM
  • Is there an easier way?

    all u hav 2 du magnifyglass error 2 find exam + poles using cstr

    less you jus cus me again maybe dat wil hep

    :)

    btw that mean joke son

    someone get this guy out of here hes just a troll, not here to help....
    Friday, November 2, 2018 9:58 PM
  • Hi

    You are making it very difficult for your readers to help you.  When your original code is way up at the top of the thread, you would do well to copy down to your new post the pertinant lines of the code.

    You can perhaps see why otherts didn't notice that you are apparently referring to a TextBox called 'txtaverage', and in which case, some of the previous points posted explain what your issue might be. Namely, you need to assign any value (as a String) to the .Text property of the TextBox as just saying 'txtaverage ="Some String"' will not work. You need to qualify that correctlymby using 'txtaverage.Text ="Some String"'


    Regards Les, Livingston, Scotland



    • Edited by leshay Friday, November 2, 2018 10:08 PM
    Friday, November 2, 2018 10:07 PM
  • Hi

    You are making it very difficult for your readers to help you.  When your original code is way up at the top of the thread, you would do well to copy down to your new post the pertinant lines of the code.

    You can perhaps see why otherts didn't notice that you are apparently referring to a TextBox called 'txtaverage', and in which case, some of the previous points posted explain what your issue might be. Namely, you need to assign any value (as a String) to the .Text property of the TextBox as just saying 'txtaverage ="Some String"' will not work. You need to qualify that correctlymby using 'txtaverage.Text ="Some String"'


    Regards Les, Livingston, Scotland



    You are making it hard for me to understand what does "correctlymby" mean??
    Friday, November 2, 2018 10:20 PM

  • Thank you but now when I am trying to calculate the average under "Private Sub btnAvg_click", nothing is being displayed into the text box for average ("txtaverage.text")

    Post the exact revised code that you are now using. We can't analyze code
    we can't see, and you have made changes to the code you posted initially.

    - Wayne

    Friday, November 2, 2018 10:39 PM
  • You are making it hard for me to understand what does "correctlymby" mean??
    So, no more help from me then.

    Regards Les, Livingston, Scotland


    • Edited by leshay Friday, November 2, 2018 11:05 PM
    Friday, November 2, 2018 10:51 PM
  • You are making it hard for me to understand what does "correctlymby" mean??

    So, no more help from me then.

    Regards Les, Livingston, Scotland


    What a great person you guys are... is it hard to explain things to people? You do know everyone starts somewhere, at one point you didnt know a thing like me currently... grow up do your job on the site and try to explain to me instead of giving up 
    Saturday, November 3, 2018 6:56 PM

  • Is there an easier way? In my course we have yet to learn what those extra commands do in VB. My teacher expects us to explain the code we right also

    While we wait for you to post the *current* code that you are working with
    so we can see if there's any issues with it, let's take a look back at the
    original code you posted. The following is a breakdown of what was happening
    in this line:

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

    Here you are concatenating the three strings and then converting the 
    resulting string to an Int. You are then dividing the sum by 3 using
    the / operator which returns a double. This is probably where the
    reference to a double came from in your error message.

    Consider this example:

    Dim grade As String = "64"
    Dim grade2 As String = "70"
    Dim grade3 As String = "82"
    
    ' This combines the three strings to get "647082" 
    ' which is then converted to an Int32
    Dim txtAverage As Int32 = CInt((grade + grade2 + grade3)) \ 3 ' = 215694
    
    ' This converts each of the three strings to integers 
    ' and then adds the three integers
    Dim txtAverage2 As Int32 = (CInt(grade) + CInt(grade2) + CInt(grade3)) \ 3 ' = 72
    
    ' Note the use of the \ operator instead of the / operator
    ' Operator \ returns an integer quotient
    ' Operator / returns a double quotient plus remainder
    
    

    References:

    \ Operator (Visual Basic)
    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/integer-division-operator

    / Operator (Visual Basic)
    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/floating-point-division-operator

    - Wayne

    • Marked as answer by Joshua Cruz 16 Sunday, November 4, 2018 12:41 AM
    Sunday, November 4, 2018 12:39 AM

  • Is there an easier way? In my course we have yet to learn what those extra commands do in VB. My teacher expects us to explain the code we right also

    While we wait for you to post the *current* code that you are working with
    so we can see if there's any issues with it, let's take a look back at the
    original code you posted. The following is a breakdown of what was happening
    in this line:

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

    Here you are concatenating the three strings and then converting the 
    resulting string to an Int. You are then dividing the sum by 3 using
    the / operator which returns a double. This is probably where the
    reference to a double came from in your error message.

    Consider this example:

    Dim grade As String = "64"
    Dim grade2 As String = "70"
    Dim grade3 As String = "82"
    
    ' This combines the three strings to get "647082" 
    ' which is then converted to an Int32
    Dim txtAverage As Int32 = CInt((grade + grade2 + grade3)) \ 3 ' = 215694
    
    ' This converts each of the three strings to integers 
    ' and then adds the three integers
    Dim txtAverage2 As Int32 = (CInt(grade) + CInt(grade2) + CInt(grade3)) \ 3 ' = 72
    
    ' Note the use of the \ operator instead of the / operator
    ' Operator \ returns an integer quotient
    ' Operator / returns a double quotient plus remainder
    
    

    References:

    \ Operator (Visual Basic)



    - Wayne

    '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 = txt1.Text
            grade2 = txt2.Text
            grade3 = txt3.Text
      ***      txtAverage.Text = CInt((grade + grade2 + grade3)) / 3        ***
    
            ' 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
    
            If grade > 100 Then
                MsgBox("TEST 1 IS GREATER THAN 100 CHECK!")
            ElseIf grade < 0 Then
                MsgBox("TEST 1 IS LESS THAN 0!")
            ElseIf 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")
            ElseIf grade2 > 100 Then
                MsgBox("Test 2 IS GREATER THAN 100! CHECK!")
            ElseIf grade2 < 0 Then
                MsgBox("Test 2 IS LESS THAN 0! CHECK!")
            ElseIf grade3 > 100 Then
                MsgBox("Test 3 IS GREATER THAN 100! CHECK!")
            ElseIf 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
    
      
        End Sub
    End Class
    
    When i click btnAverage the number isnt being averaged out its just printing whole numbers... EG-"10+10= 1010"
    I put stars where i need help... I learned turning option strict on deems numbers must equal numbers but when its flicked on i just get a whole bunch of error messages...  i tired adding "+" into the equation another thing we learned and nothing is working
    • Marked as answer by Joshua Cruz 16 Sunday, November 4, 2018 10:53 PM
    Sunday, November 4, 2018 12:59 AM


  •     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 = txt1.Text
            grade2 = txt2.Text
            grade3 = txt3.Text
      ***      txtAverage.Text = CInt((grade + grade2 + grade3)) / 3        ***
    
    
    When i click btnAverage the number isnt being averaged out its just printing whole numbers... EG-"10+10= 1010"
    I put stars where i need help... 

    I already explained in detail in my last post what is wring with the 
    starred line, and I gave you a corrected version of it. Try it before
    we address any other issues.

    - Wayne


    Sunday, November 4, 2018 1:15 AM

  •   ***      txtAverage.Text = CInt((grade + grade2 + grade3)) / 3        ***
     
    
    When i click btnAverage the number isnt being averaged out its just printing whole numbers... EG-"10+10= 1010"
    I put stars where i need help... I learned turning option strict on deems numbers must equal numbers but when its flicked on i just get a whole bunch of error messages...  i tired adding "+" into the equation another thing we learned and nothing is working

    If you changed the starred line in your last post to match the code
    example I gave you, you should see output similar to this:

    The layout may be different, and it lacks the Exit button, but you can
    see that your calculations appear to be reasonable. The only change I
    made was to the starred line so that it has the needed corrections I
    described previously. I haven't tested your error checking routines.

    The issues with Option Strict can be explained individually once you
    get to the point of having output such as this. Fundamentally, most
    errors that appear when Strict is enabled arise because you are trying
    to convert from one type to another without invoking the necessary
    conversion methods. Such as casts, methods, etc. Like ToString()
    or ToInt(), etc.

    With Strict off, the compiler will often/usually do an implicit conversion
    from one type to another whenever it can. So it will automatically convert
    from a string to an integer or vice versa.

    - Wayne

    Sunday, November 4, 2018 2:07 AM