I am trying to build a Football Scoreboard and I have performed alot of editing but I am getting hung up on this error Error 1 Variable 'strScore' hides a variable in an enclosing block. C:\Users\Michael\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 41 17 WindowsApplication1

it keeps referring to this line of code -Dim strScore As Double = Double.Parse(InputBox(strInputMessage & intNumberOfEntries + 1, strInputHeading, " "))

Perhaps I am thinking to much into it I am new to Visual Basic, Can someone help or make a suggestion? Below is my entire code.

Option Strict On
Public Class Form1

Private Sub btnEnterScore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnterScore.Click

    Dim strScore As String

    Dim intScore As Integer

    Dim intFinalScore As Integer = 0

    Dim strInputMessage As String = "Enter the score for game #"

    Dim strInputHeading As String = "Football Score"

    Dim strNormalMessage As String = "Enter the score for game #"

    Dim strNonNumericError As String = "Error - Enter a number for th score #"

    Dim strNegativeError As String = "Error please enter a positive number for score #"

    Dim Cnt As Integer

    Dim intTotalScore As Integer

    Dim strCancelClicked As String = ""

    Dim intMaxNumberOfEntries As Integer = 0

    Dim intNumberOfEntries As Integer = 0


        Dim strScore As Double = Double.Parse(InputBox(strInputMessage & intNumberOfEntries + 1, strInputHeading, " "))

        If strScore = -10 Then

            Exit Do

        End If

        If IsNumeric(strScore) Then

            intFinalScore = CInt(strScore)

            If strScore > 0 Then


                intFinalScore += intScore

                intNumberOfEntries += 1

                Cnt += 1

                strInputMessage = strNormalMessage

            End If

        End If

    Loop Until intNumberOfEntries = 10 Or CInt(strScore) = -10

    lblFinalScore.Visible = True

    If intNumberOfEntries > 1 Then

        'decFinalScore = intTotalScore + decScore - 1    

        lblFinalScore.Text = "Average score per game is " & _intFinalScore / Cnt


        lblFinalScore.Text = "no score entered"

    End If

    btnEnterScore.Enabled = True

End Sub

Private Function _intFinalScore() As Integer
    Throw New NotImplementedException
End Function

End Class

4 Years
Discussion Span
Last Post by tinstaafl

If I'm not mistaken when you're using double.parse the whole string must represent a double, anything else and it crashes. By putting the inputbox right in the parse statment you can't validate the string returned from the inputbox unless you program an error trap.

Edited by tinstaafl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.