Basic I-O

The following 4 examples try to illustrate some basic input-output (IO) mechanisms in the form of keyboard and file plus some basic control mechanisms.

Keyboard Input

Source:    kbInput.bas,
Program : kbInput.exe

Objective: Provides examples of 3 keyboard input mechanisms

After the last example, understanding some basic keyboard input methods will hopefully appear relatively straight forward. However, it should be noted that the examples linked to GETKEY, INPUT and INKEY$ are only showing some simple quick-start methods that are useful for elementary program control and data input.

Program Control

Source:     progControl.bas,,,
Program : progControl.exe

Objective: There are some basic control methods common to most programming languages in the form of IF/THEN/ELSE statements, the FOR loop plus the DO and WHILE loops.

It is assumed that most people wanting to do some programming in FreeBasic will understand the principles in this annotated source code. If not, there are plenty of good websites that cover  these mechanisms in as much detail as required.

File Display

Source:     fileDisplay.bas,,
Program : fileDisplay.exe
I/O Files:  file1.txt, file2.txt

Objective: This example tries to demonstrate 2 methods of file input. The first method uses get/put, while second method uses <LINE INPUT> to read a line of text at a time.

There is no hard and fast rule to say which is the best method as it may depend on what you are trying to do. So the purpose of this example is to point out some possibilities in order to get started. Only a small part of the code is actually in the main .bas file, as most of the work is done within functions coded within and included at the head of fileDisplay.bas. Again, there are no definitive rule as to when and why you might adopt this structural split, but it could be argued that the overall objective of the program is now clearer within the main source file. In part, this example also tries to use multiple approaches, as outlined in earlier examples, simply to highlight different possibilities. In practice, you probably would be better adopting a preferred method of doing a given task rather than having too many methods to debug.

File I/O

Source:     fileIO.bas,,
Program : fileIO.exe
I/O Files:  input.txt, output.txt

Objective: This program copies an input file to an output file.  The file-file copy is performed character-by-character via the get/put commands until completion, while the file-screen is performed line-by-line.

The reason for both methods is linked to the WRITE "text" formatting, which seems to encapsulate the line buffer text in quotes. Anyway, the examples is only intended to show a basic method of working with files.