dcsimg
Results 1 to 3 of 3

Thread: High-score table parameter error

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2017
    Location
    Scotland
    Posts
    11

    High-score table parameter error

    Hi, I'm making a game where it will ask the winning player their name and will put that and their score into a .txt file. I want it to take the top 5 players and sort their scores to display in the .txt like a high-score table. To achieve this, I created a record structure called 'topscores' which contains variables of the player's name and the player's scores. Using a bubble sort, I've tried to find a solution however the following lines give me an error:

    Code:
    FileOpen(1, winners(counter).playername)
    FileOpen(1, winners(counter).winningscore)
    It tells me 'Argument not specified for parameter etc'. Here's the subroutine that contains these lines:


    Code:
    Sub highscore(ByRef winners() As topscores)
            Dim tempname As String
            Dim tempscore As Integer
            tempname = winners(0).playername
            tempscore = winners(0).winningscore
            For counter = 0 To 4
    
                winners(counter).playername = InputBox("Please enter your name")
                FileOpen(1, "h://highscore.txt", OpenMode.Input)
                winners(counter).playername = LineInput(1)
                winners(counter).winningscore = LineInput(1)
            Next
    
            If tempscore > winners(4).winningscore Then
                winners(4).winningscore = tempscore
            End If
    
            For outerloop = 3 To 0 Step -1
                For counter = 0 To outerloop
                    If winners(counter).winningscore > winners(counter + 1).winningscore Then
                        tempname = winners(counter).playername
                        tempscore = winners(counter).winningscore
                        winners(counter).playername = winners(counter + 1).playername
                        winners(counter).winningscore = winners(counter + 1).winningscore
                        winners(counter + 1).playername = tempname
                        winners(counter + 1).winningscore = tempscore
                    End If
                Next
            Next
    
            FileOpen(1, "h://highscore.txt", OpenMode.Output)
            For counter = 0 To 4
                FileOpen(1, winners(counter).playername)
                FileOpen(1, winners(counter).winningscore)
            Next
            FileClose()
        End Sub
    Can anyone explain how I got this error and how I would correct it please? Thanks.

  2. #2
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: High-score table parameter error

    Are you sure you're using VB .NET? .NET developers don't use LineInput() or FileOpen(). That makes me think you're actually using VB6.

    But my guess is you see it in your larger snippet. FileOpen() wants three parameters:
    • A file handle number to use.
    • The path to the file.
    • A file mode.


    But the lines of code you posted only give two parameters, and neither of the 2nd parameters are a path.

    I think in VB6 you would've used FilePut() there, not FileOpen(), but I'm not sure.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,398

    Re: High-score table parameter error

    Why would you want to sort the collection manually? This could really be done in one line:
    Code:
    Dim top5() As topscore = winners.OrderBy(Function(score) score.winningscore).Take(5).ToArray()
    Fiddle: Live Demo

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width