VB Code:
Public i As Integer, j As Integer
Public hiscore(1, 9) As String, v_name As String, v_score As Integer
Public game As New frm_Game, highscore As New frm_highScore
Option Explicit
Public Sub updateHiScore()
Dim tmpscore(1, 9) As String
'first populate the temp score array with the hiscore array elements
For i = 0 To 9 Step 1
tmpscore(0, i) = hiscore(0, i)
tmpscore(1, i) = hiscore(1, i)
Next i
'check if highscores should be updated
For i = 0 To 9 Step 1
If v_score > Val(hiscore(1, i)) And v_name <> hiscore(0, i) Then
'update the highscore as needed
For j = i To 8 Step 1
hiscore(0, (j + 1)) = tmpscore(0, j)
hiscore(1, (j + 1)) = tmpscore(1, j)
Next j
hiscore(0, i) = v_name
hiscore(1, i) = v_score
Exit For
ElseIf v_name = hiscore(0, i) Then
'add to the current user score
hiscore(1, i) = v_score
End If
Next i
'clear the highscore form
highscore.Cls
'now update the highscore form
highscore.Print "Name"; , , "Score"
For i = 0 To 9 Step 1
highscore.Print (i + 1) & ". " & hiscore(0, i); , , hiscore(1, i)
Next i
End Sub
VB Code:
Option Explicit
Private Sub cmd_pnt_Click(Index As Integer)
Dim v_index As Integer
'increase the user score depending which button is clicked
'make sure to add one to the index to make it not multiply by 0!
v_index = Index + 1
'v_index * 10 makes: 1 = 10, 2 = 20, 3 = 30
v_score = v_score + (v_index * 10)
'update the highscore
updateHiScore
End Sub