Ok, I'm stuck. I'm making a highscore form that will update whenever the user gets some points, and when it updates it will check if the current score is higher than any of the others, and if it is it will move that name down the list along with the other names and will place the new score where it should go.. of course, I check to make sure it isn't the same name so that it won't keep printing the score whenever it changes.. I can get it mostly working, but not totally..
Does anyone know what's wrong with this?
mod_Main
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
frm_Game
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
The game part of this is really simple, I'm just trying things out.. I took out things in the form that wouldn't be of any use for solving this for easy reading.. When running the current code, it will print to the highscore form, but it will keep putting down the same username.. It will move different usernames down, but it will put the same username down again and again.




Reply With Quote