?
Solved

Updating Text File

Posted on 2003-02-24
1
Medium Priority
?
145 Views
Last Modified: 2010-05-01
i have a game that stores the high score in a text file.

i'm adding a "second place" Label on the form but whenever i try to update the text file i keep getting the "input past end of file" error.

can anyone let me know what i am doing wrong?

here is the code:


Private Sub enterscore_Click()

If Val(playerscore) > Val(scorelabel) Then
initials = InputBox("Enter Your Initials", "First Place")
gamer = initials

Open "C:\WINDOWS\score.txt" For Output As #1
Print #1, playerscore
Print #1, gamer
Close #1

ElseIf Val(playerscore) > Val(scorelabel2) Then
initials2 = InputBox("Enter Your Initials", "Second Place")
gamer2 = initials2

Open "C:\WINDOWS\score.txt" For Output As #1
Print #1, playerscore
Print #1, gamer2
Close #1
Else
MsgBox "Try Again"
End If

' to refresh the scores
Dim HighScore, gameplayer, HighScore2, gameplayer2
Open "C:\WINDOWS\score.txt" For Input As #1
Input #1, HighScore
Input #1, gameplayer
Input #1, HighScore2
Input #1, gameplayer2
scorelabel = HighScore
gamer = gameplayer
scorelabel2 = HighScore2
gamer2 = gameplayer2
Close #1
0
Comment
Question by:RunToTheHills
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
QJohnson earned 400 total points
ID: 8008819
When you open the file for Output, you erase its contents to replace them with your own.  If you want to add to the existing contents, as seems your intent here, you have to open in Append mode.

Since you wrote only two items to the file when you last opened it for output, your attempt to read beyond the second item is generating your error.

QJ
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question