Please use this Board for QBasic related requests ( file research, programming, etc.)
Moderators:Administrator, Global Moderator
-
coder
- Newbie
- Posts:1
- Joined:Mon Mar 28, 2005 7:22 pm
Bad File Mode
Post
by coder » Tue Mar 29, 2005 4:27 pm
why do I get bad file mode with this program ?
CLS
' Define record fields.
TYPE TestRecord
NameField AS STRING * 20
ScoreField AS SINGLE
END TYPE
' Define a variable of the user type.
DIM Rec AS TestRecord
' Open the test data file.
'
DIM FileBuffer AS TestRecord
OPEN "THi3.TXT" FOR INPUT AS #1 LEN = LEN(FileBuffer)
OPEN "THO.TXT" FOR APPEND AS #2
' Calculate number of records in the file.
Max = LOF(1) / LEN(FileBuffer)
' Read and print contents of each record.
FOR I = 1 TO Max
GET #1, I, FileBuffer
PUT #2, I, FileBuffer
NEXT I
CLOSE #1
CLOSE #2
END
-
Ralph
- QBasic God
- Posts:134
- Joined:Sat Nov 06, 2004 2:27 am
- Location:Katy, Texas
Post
by Ralph » Fri Apr 01, 2005 3:01 am
Coder:
Your line,
GET #1, I, FileBuffer
only applies for a random access file, but you assigned buffer #1 to a sequential file! Therefore, the "bad file mode" error message.
Ralph. Running QuickBASIC Version 4.5, Windows XP Home Edition, Version 2002, Service Pack 2, and HP LaserJet 4L printer.
-
marko_tomas13
Post
by marko_tomas13 » Fri Apr 08, 2005 12:41 am
LEN and GET/PUT are only used with Random Access files, you however opened the files for input and append. You have to pick either a sequential file or a random file and code accordingly to that, you cannot mix the commands.