# Input from a file - known amount of data

Keywords:
Situation:

Your program needs input from the user. You know exactly how many elements you need, and what type each one is. The data can be obtained in a file.

Actions:

Use the File open, process, close pattern to open and close the file. Use the Input statement to read data.

Explanation:

Use the File open, process, close pattern to open and close the file. Processing might be like this:

Dim goals As Integer
Dim behinds as Integer
'Open file
...
Input #1, goals, behinds
'Close
...

This works best with CSV files. For example, the file might have this:

5,3

This pattern is often used for configuration. For example, you might have a moving average that uses 30 periods. You could put the 30 in a file, so that it can be changed easily.

Referenced in: