File I/O

Blitz3D Forums/Blitz3D Beginners Area/File I/O

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Like I said, the code examples from the program don't work, but I guess I'll post them:; Changing part of a file using OpenFile, SeekFile and WriteInt

; Open/create a file to Write
fileout = WriteFile("mydata.dat")

; Write the information to the file
WriteInt( fileout, 1 )
WriteInt( fileout, 2 )
WriteInt( fileout, 3 )
WriteInt( fileout, 4 )
WriteInt( fileout, 5 )

; Close the file
CloseFile( fileout )

DisplayFile( "The file as originally written", "mydata.dat" )
; Open the file and change the Third Integer

file = OpenFile("mydata.dat")
SeekFile( file, 8 ) ; Move to the third integer in the file
WriteInt( file, 9999 ) ; Replace the original value with 9999
CloseFile( file )

DisplayFile( "The file after being midified", "mydata.dat" )
WaitKey()
; **** Function Definitions follow ****

; Read the file and print it
Function DisplayFile( Tittle$, Filename$ )
Print tittle$
filein = ReadFile( Filename$ )
While Not Eof( filein )
Number = ReadInt( filein )
Print Number
Wend
CloseFile( filein )
Print
End Function
-----------------------------
; Reading and writing a file using ReadString$ and WriteString functions

; Initialise some variables for the example
String1$ = "A short string"
String2$ = "A longer string since these are variables lengths"
String3$ = "This is string3 "
String4$ = "joined to string4"

; Open a file to write to
fileout = WriteFile("mydata.dat")

; Write the information to the file
WriteString( fileout, String1 )
WriteString( fileout, String2 )
WriteString( fileout, String3 + String4)
WriteString( fileout, "Just to show you don't have to use variables" )

; Close the file
CloseFile( fileout )

; Open the file to Read
filein = ReadFile("mydata.dat")

Read1$ = ReadString$( filein )
Read2$ = ReadString$( filein )
Read3$ = ReadString$( filein )
Read4$ = ReadString$( filein )

; Close the file once reading is finished
CloseFile( filein )

Print "String Variables Read From File - mydata.dat "
Print
Print Read1
Print Read2
Print Read3
Print Read4

WaitKey()
-------------------------------
Both of these give 'Not Enough Parameters' error during compile time. What exactly does this error mean? Then I could try to figure out what is wrong