Visual Basic Input/Output

Speaker Notes

Slide 1:

These slides show using sequential files that were created in Notepad for use in Visual Basic. This I/O is definitely limited.

Slide 2:

The data file that is being read her was created in NotePad. Notice that character fields are surrounded by double quotes and numeric fields stand alone - I treated the identification number which are the first three characters as a non numeric field. I could have also surrounded the numeric fields in double quotes.

In this example, I created a final record with a identification number of 999. When this record is read it is determined to be end of file and processing stops. Each pass through the file checks to see if the current record has a IdNo of 999.

Note also that in the routine called Form_Load, I opened the file as Input #1 and when the Exit button is clicked I Close #1.

Further information is on the following slides.

Slide 3:

This is the input file that was created in notepad. Again note that fields are separate by commas and that character fields are surrounded with double quotes.

Also note that each record has the same number of fields. On the 999 record that is being used to indicate end of file, the fields after the identification number contain a space if they are a character field and a 0 if they are a numeric field.

Slide 4:

Note that when processing ends a message box is displayed. This code shows two ways to set up the message box. One assigns it to a field called Ans and one simply uses the MsgBox command. The one that assigns it to Ans has a Rem in front of it that makes it a remark for this program because I did not want to execute the same code twice.

Close #1 closes the data file and End terminates the processing.

Slide 5:

Note that when the Okay on the message is clicked, the file is closed and processing is terminated.

Slide 6:

This is the standard way to test for EOF as opposed to inserting your own end of file record in the file.

Slide 7:

This shows the code for loading the form and for clicking the three buttons Write, Clear and Exit.

Slide 8:

Data is inputted on the form by the user. When the write button is clicked, the data is written to file #1 which was defined as output and named PayX.

Slide 9:

Four records were written by the user. After the data was entered, the Write button was clicked to write the file and then the Clear button was clicked to erase the data on the screen in preparation for writing a new record.

Slide 10:

This program reads the file PayX that was created in the previous ProjWrite1.When the form load happens, the file is opened for use by the Read click event.

Slide 11:

The Read button was pressed and the first record was displayed. Note that PayHour and PriorPay were formatted as currency when they were displayed on the form.

When the Read button is pressed, the records will be shown in order until end of file is reached.

Slide 12:

I clicked the Read button to read each record in the file. Each was displayed on the screen. When the last record was displayed, I again clicked Read and since EOF(1) was reached the message box was displayed. When I click OK on the message box, file #1 will be closed and processing will end.