File streams are used to create, read and write to files. All streams are
opened as binary, with no locking capabilities (ie. all files you open are
shared). Please familiarize yourself with these file modes:
fmCreate - Create file (read/write), truncate if file exists
fmOpenRead - Open file for reading only
fmOpenWrite - Open file for writing only
fmOpenReadWrite - Open file for reading & writing
To open a file you need to pass the filename, and provide one of the
above file modes.
DIM File AS QFileStream
This will open Test.txt for reading only. To read data, you use the
methods ReadNum and ReadStr. See RAPIDQ.INC for valid numbers.
PRINT File.ReadNum(Num_SINGLE) '-- Read 4 bytes as a SINGLE number
PRINT File.ReadStr(1024) '-- Read 1024 bytes
Another approach is to store the value into a variable, you can use the
generic Read and Write routines.
File.Read(A&) '-- Read a long value and store in A&
File.Write(B#) '-- Write a double value B#
'-- or similarily, with more work:
A& = File.ReadNum(Num_LONG)
After you're done with the file, make sure you close the handle. You can
then reuse your file stream and open up another file. To test if you've
reached the end of the file, you can either compare File.Position with
File.Size or see if File.EOF is true (-1). So long as File.Position is less
than File.Size, you haven't reached the end of the file. There are actually 2
ways to test if a file exists:
IF FileExists("Test.txt") <> FALSE THEN
However, it's better just to cut this down to:
IF File.Open("Test.txt", fmOpenRead) = FALSE THEN
ShowMessage("Could not open file")
File.Open will return a non-zero number if the file was successfully
opened, 0 otherwise.