FoxPro Low Level Functions

FoxPro has always had functions to read and write binary files at a low level. The StrToFile() and FileToStr() functions introduced in Visual FoxPro gave us an easy way of handling text files but there are still times when you have to drop back to working with bytes and unprintable control characters and that's when functions like FREAD() become very useful.

The low level commands all start with "F" and if you look up any of their entries in Help then you'll find links to all the others. The five most important are:

  • FCREATE() creates a file.
  • FOPEN() opens a file.
  • FCLOSE() closes a file.
  • FREAD() reads bytes from a file.
  • FWRITE() writes bytes to a file.

These commands date back to the earliest days of FoxPro and it somehow seems more natural to write them in upper case. Even VFP9 Help still uses this convention.

Low level

These are referred to as 'low level' functions because there is very little between you and the contents of the file. For example, if you use FREAD() to read ten bytes from the file then it will try to read ten bytes starting from the current position in the file and will move its pointer ten bytes further down the file. This might make the pointer fall off the end of the file but that's your problem as a programmer.

File handles

These functions all rely on the concept of a file handle. This is an integer which is returned when you create or open a file and which you then use in all further operations on that file. You can use the DISPLAY STATUS command to see which files are associated with which file handles:

User-opened files: D:\DEV\FRED.TXT Handle=12 Pos=0 Read=Yes Write=Yes

This shows that I have a file named fred.txt open, it is associated with file handle 12, I'm at the start of the file (Position 0) and I have read and write access to the file.

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Alvechurch Data - Microsoft FoxPro and Access Database Development and Training

Alvechurch Data are based close to Birmingham and provide Microsoft Access and Visual FoxPro training, development and support.

Read More

Autocomplete in Visual Fox Pro

Autocomplete in Visual Fox Pro

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.

Read More

Development Services

Alvechurch Data specialise in Microsoft Access and Visual FoxPro databases and have fifteen years experience developing databases for small business use.

Read More

Access and Visual FoxPro Training

Microsoft Access and Visual FoxPro training courses and workshops offered by Alvechurch Data in Birmingham.

Read More

Support Services

How Alvechurch Data can help you with maintenance and support of your Access and FoxPro databases.

Read More