4 Replies - 1880 Views - Last Post: 29 April 2012 - 11:27 AM Rate Topic: -----

#1 imckinn40  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 19-March 12

I having problems with assignment

Posted 29 April 2012 - 10:26 AM

I'm having problems with my visual basic assignment. The program will run, but it won't allow me to input the score. It keep saying error put in positive number. But that won't work also. I've checked for errors and used debugging. I can't see what's wrong. This is what I have.

' Program Name: Football Fever Scoreboard
' Author:       Iris Mckinney   
' Date:         April 25, 2012
' Purpose:      This application calculates the points
'               scored during a football game by one team.
Option Strict On

Public Class lblFootballFeverScoreboard

    ' The btnEnterScore event accepts and displays up to ten scores
    ' from the user, and then print last score.

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

        Dim strScore As String
        Dim decScore As Decimal
        Dim decFinalScore As Decimal = 0D
        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 the score #"
        Dim strNegativeError As String = "Error please enter a positive number for score #"
        Dim decTotalScore As Decimal

        Dim strCancelClicked As String = ""
        Dim intMaxNumberOfEntries As Integer = 10
        Dim intNumberOfEntries As Integer = 1

        ' This loop allows the user to enter the Football Scores of up to
        ' 10 scores. The loop terminates when the user has entered 10
        ' scores.

        strScore = InputBox(strInputMessage & intNumberOfEntries, strInputHeading, " ")

        Do Until intNumberOfEntries > intMaxNumberOfEntries Or strScore = strCancelClicked

            If IsNumeric(strScore) Then
                decFinalScore = Convert.ToDecimal(strScore)
                If decScore > 0 Then
                    lstScoreboard.Items.Add(decScore)
                    decFinalScore += decScore
                    intNumberOfEntries += 1
                    strInputMessage = strNormalMessage
                Else
                    strInputMessage = strNegativeError
                End If

            Else
                strInputMessage = strNonNumericError
            End If

            If intNumberOfEntries <= intMaxNumberOfEntries Then
                strScore = InputBox(strInputMessage & intNumberOfEntries, strInputHeading, " ")
            End If

        Loop
        lblFinalScore.Visible = True

        If intNumberOfEntries > 1 Then
            decFinalScore = decTotalScore + decScore - 1
            lblFinalScore.Text = "Average score per game is " & _
                decFinalScore.ToString("F1") & "average score"
        Else
            lblFinalScore.Text = "no score entered"
        End If
        btnEnterScore.Enabled = False


    End Sub

End Class



Is This A Good Question/Topic? 0
  • +

Replies To: I having problems with assignment

#2 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 205
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: I having problems with assignment

Posted 29 April 2012 - 10:43 AM

So the program checks the If statement at line 39 and jumps to the Else part, am I right? What's the value of the variable decScore?

And are you using Inputboxes to output error messages? You can easily use MessageBox instead.

This post has been edited by nK0de: 29 April 2012 - 10:47 AM

Was This Post Helpful? 0
  • +
  • -

#3 kojima100  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 66
  • Joined: 10-November 10

Re: I having problems with assignment

Posted 29 April 2012 - 10:44 AM

The problem is you never assign any value to decScore. Check to see if decFinalScore is more than 0 instead.
Was This Post Helpful? 0
  • +
  • -

#4 imckinn40  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 19-March 12

Re: I having problems with assignment

Posted 29 April 2012 - 11:21 AM

I thought the value was 0 should it be something else.
Was This Post Helpful? 0
  • +
  • -

#5 kojima100  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 66
  • Joined: 10-November 10

Re: I having problems with assignment

Posted 29 April 2012 - 11:27 AM

Yes it is 0, which is why your code says you need to input a positive number. Since you don't actually use at all in your code apart from that check, i assume you wish to check decFinalScore instead.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1