visual basic i/o programs (projread1, projread2, projwrite1, projpay) please use speaker notes for...
TRANSCRIPT
![Page 1: Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!](https://reader036.vdocuments.site/reader036/viewer/2022082506/5697c0131a28abf838ccc825/html5/thumbnails/1.jpg)
Visual Basic I/O Programs(ProjRead1, ProjRead2, ProjWrite1, ProjPay)
Please use speaker notes for additional information!
![Page 2: Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!](https://reader036.vdocuments.site/reader036/viewer/2022082506/5697c0131a28abf838ccc825/html5/thumbnails/2.jpg)
ProjRead1ProjRead1
![Page 3: Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!](https://reader036.vdocuments.site/reader036/viewer/2022082506/5697c0131a28abf838ccc825/html5/thumbnails/3.jpg)
ProjRead1ProjRead1
Private Sub Form_Load() Open "A:\StudentA" For Input As #1End Sub
When the form is loaded, the StudentA file will be opened as Input (meaning it can be read). It is opened as #1. If a second file was opened, it could be opened as #2.
![Page 4: Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!](https://reader036.vdocuments.site/reader036/viewer/2022082506/5697c0131a28abf838ccc825/html5/thumbnails/4.jpg)
ProjRead1ProjRead1
Private Sub cmdRead_Click() Dim IdNo As String, Name As String, Major As String, GPA As String, NumCr As String Dim Ans As String Input #1, IdNo, Name, Major, GPA, NumCr If IdNo = "999" Then Rem Ans = MsgBox("End of File Reached", vbOKOnly, "EOF") MsgBox "End of File Reached", vbOKOnly, "EOF" Rem END and Close here terminate the program Close #1 End Else txtIdNo.Text = IdNo txtName.Text = Name txtMajor.Text = Major txtGPA.Text = GPA txtNumCr.Text = NumCr End IfEnd Sub
In cmdRead, I define the fields on the file. In the example, I defined them as all string. Since the last two fields were numeric, I could also have defined that as Single and/or Integer as shown below.
Dim IdNo As String, Name As String, Major As String, GPA As Single, NumCr As Integer
Input #1 relates to the file that was opened For Input as #1. This statement refers to the fields by the names that were defined in the Dim statements above.
IdNo is checked to see if it is 999. If it is, processing will end.
If IdNo is not 999, the data from the input record is moved to the text boxes on the form.
![Page 5: Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!](https://reader036.vdocuments.site/reader036/viewer/2022082506/5697c0131a28abf838ccc825/html5/thumbnails/5.jpg)
The results of clicking Read are shown above. Only the first three records are shown.
After the last record has been read, I pressed Read again. The record with Idno = 999 was read and this indicated that end of file had been reached. The message was displayed.
![Page 6: Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!](https://reader036.vdocuments.site/reader036/viewer/2022082506/5697c0131a28abf838ccc825/html5/thumbnails/6.jpg)
ProjRead2ProjRead2
Note that because I am testing for EOF(1) instead of IdNo=999, the 999 record will show. When I press Read with the 999 record on the screen, the EOF message is displayed.
IF EOF(1) tests to see if end of file has been reached on the file opened as #1.
![Page 7: Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!](https://reader036.vdocuments.site/reader036/viewer/2022082506/5697c0131a28abf838ccc825/html5/thumbnails/7.jpg)
ProjWrite1ProjWrite1
![Page 8: Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!](https://reader036.vdocuments.site/reader036/viewer/2022082506/5697c0131a28abf838ccc825/html5/thumbnails/8.jpg)
ProjWrite1ProjWrite1
Private Sub Form_Load() Open "A:\PayX" For Output As #1End Sub
When the form is loaded, a file is opened for Output called PayX. The file is opened as #1 since it is the only file being used in the code.
Private Sub cmdWrite_Click() Write #1, txtName.Text, txtPayHour.Text, txtHours.Text, txtExempt.Text, txtMarital.Text, txtPriorPay.TextEnd Sub
When the Write button is clicked, the write command writes the data that was inputted into the text boxes on the form.
Private Sub cmdExit_Click() Close #1 EndEnd Sub
When the Exit button is clicked, file #1 is closed and processing is ended.
Private Sub cmdClear_Click() txtName.Text = "" txtPayHour.Text = "" txtHours.Text = "" txtExempt.Text = "" txtMarital.Text = "" txtPriorPay.Text = "" txtName.SetFocusEnd Sub
When the Clear button is clicked, the data in the text boxes on the form is cleared out and the fields are set to null values with “”.
![Page 9: Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!](https://reader036.vdocuments.site/reader036/viewer/2022082506/5697c0131a28abf838ccc825/html5/thumbnails/9.jpg)
ProjWrite1ProjWrite1
![Page 10: Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!](https://reader036.vdocuments.site/reader036/viewer/2022082506/5697c0131a28abf838ccc825/html5/thumbnails/10.jpg)
ProjPayProjPay
When the form is loaded, not data is displayed. Clicking the Read button will display the record on the screen.
![Page 11: Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!](https://reader036.vdocuments.site/reader036/viewer/2022082506/5697c0131a28abf838ccc825/html5/thumbnails/11.jpg)
ProjPayProjPay
![Page 12: Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!](https://reader036.vdocuments.site/reader036/viewer/2022082506/5697c0131a28abf838ccc825/html5/thumbnails/12.jpg)
ProjPayProjPay
The last record has been displayed and the Read button is clicked. At that point the EOF message box is displayed.