Calculate new high score

storing a value in a variable after completing function

Page 1 of 1

3 Replies - 2363 Views - Last Post: 27 April 2009 - 11:15 PM Rate Topic: -----

#1 hfinny  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-April 09

Calculate new high score

Post icon  Posted 27 April 2009 - 08:08 PM

I am working on a simple application that has 4 text boxes.
1 - enter score
2. - total number of scores
3. average score
4. - highest score.

I need to calculate the high score and am having trouble storing a value that represents the previous high score, and the comparator funcion. Does anyone have some suggestions?

_______________________________________________________
Module modCalculations
Public n_sErrorTitle As String = "Entry Error"
'Count the number of entered scores
Dim intCount As Integer
Public Function NumberOfScores(ByVal Score As Decimal)

intCount += 1
NumberOfScores = intCount

End Function

_____________________________________________________

'add the scores, save the total of scores, and divide by the number of scores to create average
Dim dSumOfScores As Decimal
Public Function AverageScore(ByVal Score As Decimal)

Dim dScore As Decimal
Dim dAverage As Decimal
Dim dTotal As Decimal

dScore = Score
dSumOfScores = dSumOfScores + dScore
dAverage = dSumOfScores / intCount

AverageScore = dAverage
End Function

________________________________________________________

Dim dOldHighScore As Decimal
Public Function HighScore(ByVal NewScore As Decimal)

Dim dCompareScores As Decimal = 0
Dim dNewScore As Decimal
dNewScore = NewScore

If dNewScore > dCompareScores Then
dOldHighScore = dNewScore
Else
dOldHighScore = dOldHighScore
End If

HighScore = dOldHighScore
End Function

___________________________________________________

Public Sub ValidateNumericEntry(ByVal Value1 As String, _
ByRef ValidEntry As Boolean)
If IsNumeric(Value1) Then
If Value1 > 0 And Value1 < 100 Then
ValidEntry = True
End If
End If
End Sub

End Module

Is This A Good Question/Topic? 0
  • +

Replies To: Calculate new high score

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: Calculate new high score

Posted 27 April 2009 - 08:35 PM

The line If dNewScore > dCompareScores Then should probably be if dNewScore > dOldHighScore then You want to be comparing the incoming new score to the old high score and if it is greater, then set the dOldHighScore to this new score.

You also don't need the else in this situation because the line dOldHighScore = dOldHighScore means nothing.

So a simple if statement is all you need, no else. You will simply set the dOldHighScore only when dNewScore is greater. Otherwise you leave it alone. :)
Was This Post Helpful? 0
  • +
  • -

#3 hfinny  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-April 09

Re: Calculate new high score

Posted 27 April 2009 - 08:48 PM

View Posthfinny, on 27 Apr, 2009 - 07:08 PM, said:

I am working on a simple application that has 4 text boxes.
1 - enter score
2. - total number of scores
3. average score
4. - highest score.

I developed a method to clear the text boxes, and memory. However, it only clears the textboxes. Is there a Clear Method that is used for this>

I need to calculate the high score and am having trouble storing a value that represents the previous high score, and the comparator funcion. Does anyone have some suggestions?

_______________________________________________________
Module modCalculations
Public n_sErrorTitle As String = "Entry Error"
'Count the number of entered scores
Dim intCount As Integer
Public Function NumberOfScores(ByVal Score As Decimal)

intCount += 1
NumberOfScores = intCount

End Function

_____________________________________________________

'add the scores, save the total of scores, and divide by the number of scores to create average
Dim dSumOfScores As Decimal
Public Function AverageScore(ByVal Score As Decimal)

Dim dScore As Decimal
Dim dAverage As Decimal
Dim dTotal As Decimal

dScore = Score
dSumOfScores = dSumOfScores + dScore
dAverage = dSumOfScores / intCount

AverageScore = dAverage
End Function

________________________________________________________

Dim dOldHighScore As Decimal
Public Function HighScore(ByVal NewScore As Decimal)

Dim dCompareScores As Decimal = 0
Dim dNewScore As Decimal
dNewScore = NewScore

If dNewScore > dCompareScores Then
dOldHighScore = dNewScore
Else
dOldHighScore = dOldHighScore
End If

HighScore = dOldHighScore
End Function

___________________________________________________

Public Sub ValidateNumericEntry(ByVal Value1 As String, _
ByRef ValidEntry As Boolean)
If IsNumeric(Value1) Then
If Value1 > 0 And Value1 < 100 Then
ValidEntry = True
End If
End If
End Sub

End Module

Was This Post Helpful? 0
  • +
  • -

#4 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Re: Calculate new high score

Posted 27 April 2009 - 11:15 PM

Not sure why you quoted that.

please place the code in the [ code] tags.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1