Ad blocker detected: Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker on our website.
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
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.
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.