Working with Files
You may directly work with files; i.e. to save or retrieve your own data in the desired format.
A file may be in Text (human readable) or Binary formats.
The following example shows how to write in a file:
File f
FileOpen "C:/MPE/test_file.txt" For Writing Text In f
FileWriteString('Hello World.',f);
FileClose(f);
and, the following example shows how read from a file:
File f
FileOpen "C:/MPE/test_file.txt" For Reading Text In f
String str
str = FileReadString(100,f);//Read at most 100 characters or a full line
FileClose(f);
Println str
MsgBoxInfo str
To work with binary files, use the following functions for reading:
| FileRead1b | Reads 1 byte (signed) from a file |
| FileRead1bu | Reads 1 byte (Unsigned) from a file |
| FileRead2b | Reads 2 byte (signed) from a file |
| FileRead2bu | Reads 2 byte (Unsigned) from a file |
| FileRead4bf | Reads 4 byte (signed float) from a file |
| FileRead4bi | Reads 4 byte (signed integer) from a file |
| FileRead4bu | Reads 4 byte (Unsigned integer) from a file |
| FileRead8b | Reads 8 byte (signed double) from a file |
and the followings for writing
| FileWrite1b | Wirtes 1 byte (signed) into a file | |
| FileWrite1bu | Wirtes 1 byte (Unsigned) into a file | |
| FileWrite2b | Wirtes 2 byte (signed) into a file | |
| FileWrite2bu | Wirtes 2 byte (Unsigned) into a file | |
| FileWrite4bf | Wirtes 4 byte (signed float) into a file | |
| FileWrite4bi | Wirtes 4 byte (signed integer) into a file | |
| FileWrite4bu | Wirtes 4 byte (Unsigned integer) into a file | |
| FileWrite8b | Wirtes 8 byte (signed double) into a file |
Look at the following examples:
Writing Binary in Files:
File f
FileOpen "C:/MPE/test_file.bin" //For Writing Binary In f
Float m
m=-105.23
Integer i
i=300
FileWrite4bf(f,m);
FileWrite4bi(f,i);
FileClose(f);
Reading Binary From Files:
File f
FileOpen "C:/MPE/test_file.bin" //For Reading Binary In f
Float m
Integer i
m=FileRead4bf(f);
i=FileRead4bi(f);
FileClose(f);