Hello im new to visual basic, i'm on 2005 and need a little help with a project im doing. Once this code is executed an input box pops up and asks for a football score, once the score is entered it is displayed in a listbox like this.
Points Scored 6 Total Points 6
Now the problem is when i enter the second score from the next inputbox i'm getting the problem.
Points Scored 6 Total Points 6
Points Scored 3 Total Points 6
etc.
What i need is the Total Points Column to add the values as the input is entered, but the first Score in total points needs to remain the same.
This is an example of what i need.
Points Scored 6 Total Points 6
Points Scored 3 Total Points 9
Points Scored 6 Total Points 15
The loop is ran until the user clicks the cancel button. I dont know exactly what i need to do to make this happen, but if someone could help pointing me in the right direction it would be appreciated. Heres the full code.
Points Scored 6 Total Points 6
Now the problem is when i enter the second score from the next inputbox i'm getting the problem.
Points Scored 6 Total Points 6
Points Scored 3 Total Points 6
etc.
What i need is the Total Points Column to add the values as the input is entered, but the first Score in total points needs to remain the same.
This is an example of what i need.
Points Scored 6 Total Points 6
Points Scored 3 Total Points 9
Points Scored 6 Total Points 15
The loop is ran until the user clicks the cancel button. I dont know exactly what i need to do to make this happen, but if someone could help pointing me in the right direction it would be appreciated. Heres the full code.
Code:
Option Strict On
Option Explicit On
Public Class frmScoreboard
Private Sub mnuEnterScoreItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEnterScoreItem.Click
'Declare and initialize variables
Dim strPointsScored As String
Dim decPointsScored As Decimal
Dim strTotalScore2 As String
Dim decTotalScore2 As Decimal
Dim strTotalScore As String
Dim decTotalScore As Decimal
Dim decFinalScore As Decimal = 0D
Dim strInputBoxMessage As String = "Enter score #"
Dim strInputBoxHeading As String = "Points Scored"
Dim strNormalBoxMessage As String = "Enter score #"
Dim strNonNumericError As String = "Please enter a numeric value for score #"
Dim strNegativeNumberError As String = "Please enter a positive value for score #"
'Declare and initialize loop variables
Dim intNumberOfEntries As Integer = 1
strPointsScored = InputBox(strInputBoxMessage _
& intNumberOfEntries, strInputBoxHeading, " ")
strTotalScore = strPointsScored
strTotalScore2 = strTotalScore
Do Until (strPointsScored = "")
If IsNumeric(strPointsScored) Then
decPointsScored = Convert.ToDecimal(strPointsScored)
decTotalScore = Convert.ToDecimal(strTotalScore)
decTotalScore2 = Convert.ToDecimal(strTotalScore2)
If decPointsScored > 0 Then
Me.lstScores.Items.Add("Points scored " & decPointsScored & _
"Total Points " & decTotalScore2)
decFinalScore = decPointsScored + decTotalScore2
intNumberOfEntries += 1
strInputBoxMessage = strNormalBoxMessage
decTotalScore2 += Me.lstScores.Items.Add(decTotalScore)
Else
strInputBoxMessage = strNegativeNumberError
End If
Else
strInputBoxMessage = strNonNumericError
End If
If intNumberOfEntries > 0 Then
strPointsScored = InputBox(strInputBoxMessage _
& intNumberOfEntries, strInputBoxHeading)
End If
Loop
Me.lblFinalScore.Visible = True
If intNumberOfEntries > 1 Then
Me.lblFinalScore.Text = "The Final Score is " & _
decFinalScore.ToString("F1")
Else
Me.lblFinalScore.Text = "No score entered"
End If
End Sub
End Class
Comment