Calculate new high score

Page 1 of 1

3 Replies - 3148 Views - Last Post: 27 April 2009 - 11:15 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=102035&amp;s=e3d646fd80ca73295a312d15687738a4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 hfinny

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

Calculate new high score

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

• Programming Theoretician

Reputation: 5186
• Posts: 13,916
• 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.

#3 hfinny

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

Re: Calculate new high score

Posted 27 April 2009 - 08:48 PM

hfinny, 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

#4 firebolt

• D.I.C Lover

Reputation: 93
• 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.