Saving a high score in vb
Saving a high score in vb
Saving a high score in vb
Saving a high score in vb
Saving a high score in vb
Saving a high score in vb Saving a high score in vb Saving a high score in vb Saving a high score in vb Saving a high score in vb Saving a high score in vb Saving a high score in vb Saving a high score in vb
Saving a high score in vb Saving a high score in vb
Saving a high score in vb
Go Back  Xtreme Visual Basic Talk > > > Saving a high score in vb


Reply
 
Thread Tools Display Modes
  #1  
Old 12-09-2013, 01:58 PM
SCS17 SCS17 is offline
Newcomer
 
Join Date: Nov 2013
Posts: 3
Default Saving a high score in vb


For a project at school I have to save a persons score and initials in a high score table which has a limit of 10 using a record structure and saving the scores in a text file how do I do this?
I do have a high score table now but I have no idea how to do this using a record structure.
Reply With Quote
  #2  
Old 12-09-2013, 04:16 PM
Gruff's Avatar
GruffSaving a high score in vb Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Welcome to the forum SCS17. Don't forget to read the forum Posting Guidelines.

Could you be more specific about your table and record structure?

A bit of your code would also go a long way tward us gaining an understanding of what you need to do.

As it sits I do not know if you are talking about a random access file or a sequential text file.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #3  
Old 12-10-2013, 03:52 PM
SCS17 SCS17 is offline
Newcomer
 
Join Date: Nov 2013
Posts: 3
Default

It should be using a random access file. This is the code I have so far. I have to change it so it does the same function but is saved using records not just file handling. The program is written in vb6.

Code:
Dim Scores(1 To 10) As Integer
Dim names(1 To 10) As String
Dim game1(1 To 10) As String
Dim game2(1 To 10) As Integer
Dim userscore As Integer
Dim username As String
Dim a As Integer
Dim b As Integer
Dim x As Integer

Private Sub cmdsavescore_Click()

'sort the new score
For x = 1 To 10
    a = Scores(x)
    If userscore >= a Then
        game1(x) = username
        game2(x) = userscore
            For b = x + 1 To 10
                game1(b) = names(b - 1)
                game2(b) = Scores(b - 1)
            Next
            Call newscore
            Exit Sub
    End If
    game1(x) = names(x)
    game2(x) = Scores(x)
Next
End Sub

Private Sub Form_Load()

Open "C:/high scores.txt" For Input As #1
a = 1
While Not EOF(1)
    Input #1, names(a), Scores(a)
        a = a + 1
    Wend
Close #1
Call highscore(x)
End Sub
Private Sub highscore(x As Integer)
For x = 1 To 10
    List1.AddItem names(x)
    List2.AddItem Scores(x)
Next
End Sub
Private Sub newscore()
'clear the list boxes
List1.Clear
List2.Clear
' save a new score
For x = 1 To 10
    List1.AddItem game1(x)
    List2.AddItem game2(x)
    names(x) = game1(x)
    Scores(x) = game2(x)
Next
Open "C:\high scores.txt" For Output As #1
For x = 1 To 10
    Print #1, names(x) & "," & Scores(x)
Next
Close #1
End Sub

Last edited by passel; 12-11-2013 at 12:53 AM. Reason: Added [code][/code] tags
Reply With Quote
  #4  
Old 12-11-2013, 01:01 AM
passel's Avatar
passelSaving a high score in vb passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

So that code works properly and you just need to change it to use a structure and Random Access file? It just seems in briefly looking at it, that is wouldn't work properly, like it might duplicate a new high users name when it added to the list, but not taking the time to actually try it, I could be wrong.
Unfortunately, too late at night for me to help much, should have been in bed a couple of hours ago, at least. You might want to see if you can get anything out of the File I/O Tutorial.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply

Tags
game, high, records, score, text file


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Saving a high score in vb
Saving a high score in vb
Saving a high score in vb Saving a high score in vb
Saving a high score in vb
Saving a high score in vb
Saving a high score in vb Saving a high score in vb Saving a high score in vb Saving a high score in vb Saving a high score in vb Saving a high score in vb Saving a high score in vb
Saving a high score in vb
Saving a high score in vb
 
Saving a high score in vb
Saving a high score in vb
 
-->