Page 1 of 1

Bad File Mode

Posted: Tue Mar 29, 2005 4:27 pm
by coder
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

Posted: Fri Apr 01, 2005 3:01 am
by Ralph
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.

Posted: Fri Apr 08, 2005 12:41 am
by marko_tomas13
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.