Results 1 to 7 of 7

Thread: dynamic highscore form

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    dynamic highscore form

    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:
    1. Public i As Integer, j As Integer
    2. Public hiscore(1, 9) As String, v_name As String, v_score As Integer
    3. Public game As New frm_Game, highscore As New frm_highScore
    4. Option Explicit
    5. Public Sub updateHiScore()
    6.   Dim tmpscore(1, 9) As String
    7.   'first populate the temp score array with the hiscore array elements
    8.   For i = 0 To 9 Step 1
    9.     tmpscore(0, i) = hiscore(0, i)
    10.     tmpscore(1, i) = hiscore(1, i)
    11.   Next i
    12.   'check if highscores should be updated
    13.   For i = 0 To 9 Step 1
    14.     If v_score > Val(hiscore(1, i)) And v_name <> hiscore(0, i) Then
    15.     'update the highscore as needed
    16.       For j = i To 8 Step 1
    17.         hiscore(0, (j + 1)) = tmpscore(0, j)
    18.         hiscore(1, (j + 1)) = tmpscore(1, j)
    19.       Next j
    20.       hiscore(0, i) = v_name
    21.       hiscore(1, i) = v_score
    22.       Exit For
    23.     ElseIf v_name = hiscore(0, i) Then
    24.       'add to the current user score
    25.       hiscore(1, i) = v_score
    26.     End If
    27.   Next i
    28.   'clear the highscore form
    29.   highscore.Cls
    30.   'now update the highscore form
    31.   highscore.Print "Name"; , , "Score"
    32.   For i = 0 To 9 Step 1
    33.     highscore.Print (i + 1) & ". " & hiscore(0, i); , , hiscore(1, i)
    34.   Next i
    35. End Sub

    frm_Game
    VB Code:
    1. Option Explicit
    2. Private Sub cmd_pnt_Click(Index As Integer)
    3.   Dim v_index As Integer
    4.   'increase the user score depending which button is clicked
    5.   'make sure to add one to the index to make it not multiply by 0!
    6.   v_index = Index + 1
    7.   'v_index * 10 makes: 1 = 10, 2 = 20, 3 = 30
    8.   v_score = v_score + (v_index * 10)
    9.   'update the highscore
    10.   updateHiScore
    11. 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.
    Like Archer? Check out some Sterling Archer quotes.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Your code doesn't show where v_name comes from so I added a textbox and did this.

    VB Code:
    1. Private Sub cmd_pnt_Click(Index As Integer)
    2.   Dim v_index As Integer
    3.   [b]v_name = Text1.Text[/b]
    4.   'increase the user score depending which button is clicked
    5.   'make sure to add one to the index to make it not multiply by 0!
    6.   v_index = Index + 1
    7.   'v_index * 10 makes: 1 = 10, 2 = 20, 3 = 30
    8.   v_score = v_score + (v_index * 10)
    9.   'update the highscore
    10.   updateHiScore
    11. End Sub
    When I did and put a different name in the textbox each time I clicked the button, it worked OK.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    v_name is defined in frm_Game with my txt_name textbox.

    Did you click on the points command button multiple times for each name? If you did and it worked fine, I'll try that.
    Like Archer? Check out some Sterling Archer quotes.

  4. #4

  5. #5

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    if you don't click the button more than once for each name you won't see the problem i'm having..

    edit: there's probably some of my 'test code' left somewhere in there too.
    Attached Files Attached Files
    Like Archer? Check out some Sterling Archer quotes.

  7. #7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width