VERSION 5.00 Begin VB.Form frmInputOutput BackColor = &H00C0C0C0& Caption = "Tom's Phone List" ClientHeight = 4740 ClientLeft = 60 ClientTop = 345 ClientWidth = 4680 ScaleHeight = 4740 ScaleWidth = 4680 StartUpPosition = 3 'Windows Default Begin VB.CommandButton cmdDisplayRecs Caption = "Display &Records" Height = 255 Left = 720 TabIndex = 13 Top = 3360 Width = 3135 End Begin VB.CommandButton cmdSortList Caption = "&Sort List" Height = 255 Left = 720 TabIndex = 11 Top = 3000 Width = 3135 End Begin VB.CommandButton cmdExit Caption = "E&xit" Default = -1 'True Height = 315 Left = 1320 TabIndex = 10 Top = 4080 Width = 1695 End Begin VB.CommandButton cmdAppend Caption = "&Add New Entry" Height = 255 Left = 720 TabIndex = 9 Top = 2640 Width = 3135 End Begin VB.CommandButton cmdInput Caption = "&Print List" Height = 255 Left = 720 TabIndex = 8 Top = 2280 Width = 3135 End Begin VB.CommandButton cmdOutput Caption = "&Make New File" Height = 255 Left = 720 TabIndex = 7 Top = 1920 Width = 3135 End Begin VB.TextBox txtPhone Height = 285 Left = 3480 TabIndex = 3 Top = 1200 Width = 1095 End Begin VB.TextBox txtLastName Height = 285 Left = 1560 TabIndex = 2 Top = 1200 Width = 1815 End Begin VB.TextBox txtFirstName Height = 285 Left = 0 TabIndex = 1 Top = 1200 Width = 1455 End Begin VB.PictureBox picOutput Height = 615 Left = 0 ScaleHeight = 555 ScaleWidth = 4515 TabIndex = 0 Top = 0 Width = 4575 End Begin VB.Label lblProgName Caption = "This Listing programmed by Tom Reilly for CS101 Spring 2002" Height = 255 Left = 120 TabIndex = 12 Top = 4440 Width = 4455 End Begin VB.Label lblGrade Caption = "Phone Number" Height = 255 Left = 3480 TabIndex = 6 Top = 1560 Width = 1095 End Begin VB.Label lblLname Caption = "Last Name" Height = 255 Left = 1560 TabIndex = 5 Top = 1560 Width = 1815 End Begin VB.Label lblFname Caption = "First Name" Height = 255 Left = 0 TabIndex = 4 Top = 1560 Width = 1455 End End Attribute VB_Name = "frmInputOutput" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim strFileName As String Dim strFirstNamesArray() As String, strLastNamesArray() As String, strPhoneNumArray() As String 'Total Number of Records Dim intRecCount As Integer 'Counter for writing single records Dim intSingleRecCount As Integer Private Sub cmdAppend_Click() Dim strFirstName As String Dim strLastName As String Dim strPhone As String strFileName = "TomsPhoneFile.txt" strFileName = InputBox("Please enter file name ", "Enter File Name", strFileName) strFirstName = txtFirstName.Text strLastName = txtLastName.Text strPhone = txtPhone.Text Open App.Path & "\" & strFileName For Append As #1 Write #1, strFirstName, strLastName, strPhone MsgBox "Data Appended to " & strFileName Close #1 txtFirstName.Text = "" txtLastName.Text = "" txtPhone.Text = "" End Sub Private Sub cmdDisplayRecs_Click() Call printSingleRecord End Sub Private Sub cmdExit_Click() End End Sub Private Sub cmdInput_Click() Dim strFirstName As String Dim strLastName As String Dim strPhone As String strFileName = "TomsPhoneFile.txt" strFileName = InputBox("Please enter file name ", "Enter File Name", strFileName) Printer.Print "First Name"; Tab(20); "Last Name"; Tab(40); "Phone" Open App.Path & "\" & strFileName For Input As #1 Do While Not EOF(1) Input #1, strFirstName, strLastName, strPhone Printer.Print strFirstName; Tab(20); strLastName; Tab(40); strPhone Loop Close #1 Printer.EndDoc End Sub Private Sub cmdOutput_Click() Dim strFirstName As String Dim strLastName As String Dim strPhone As String strFileName = "TomsPhoneFile.txt" MsgBox ("WARNING!!!! THIS OPERATION WILL ERASE ANY EXISTING INFORMATION IN " & strFileName) strFileName = InputBox("Please enter file name ", "Enter File Name", strFileName) strFirstName = txtFirstName.Text strLastName = txtLastName.Text strPhone = txtPhone.Text Open App.Path & "\" & strFileName For Output As #1 Write #1, strFirstName, strLastName, strPhone MsgBox "Data Saved to " & strFileName Close #1 txtFirstName.Text = "" txtLastName.Text = "" txtPhone.Text = "" End Sub Private Sub cmdSortList_Click() Dim passNum As Integer, i As Integer, tempLName As String, tempFName As String, tempPhone As String intRecCount = getRecordCount() Call populateArrays For passNum = 1 To (intRecCount - 1) For i = 1 To intRecCount - passNum If strLastNamesArray(i) > strLastNamesArray(i + 1) Then tempFName = strFirstNamesArray(i) tempLName = strLastNamesArray(i) tempPhone = strPhoneNumArray(i) strFirstNamesArray(i) = strFirstNamesArray(i + 1) strLastNamesArray(i) = strLastNamesArray(i + 1) strPhoneNumArray(i) = strPhoneNumArray(i + 1) strFirstNamesArray(i + 1) = tempFName strLastNamesArray(i + 1) = tempLName strPhoneNumArray(i + 1) = tempPhone End If Next i Next passNum 'Call printArrays End Sub Public Function getRecordCount() Dim tempFirstName As String, tempLastName As String, tempPhone As Single Dim recCount As Integer strFileName = "TomsPhoneFile.txt" strFileName = InputBox("Please enter file name ", "Enter File Name", strFileName) recCount = 0 Open App.Path & "\" & strFileName For Input As #1 Do While Not EOF(1) Input #1, tempFirstName, tempLastName, tempPhone recCount = recCount + 1 Loop Close #1 getRecordCount = recCount End Function Private Sub populateArrays() Dim i As Integer ReDim strFirstNamesArray(1 To intRecCount), strLastNamesArray(1 To intRecCount), strPhoneNumArray(1 To intRecCount) Open App.Path & "\" & strFileName For Input As #1 For i = 1 To intRecCount Input #1, strFirstNamesArray(i), strLastNamesArray(i), strPhoneNumArray(i) Next i Close #1 End Sub Public Sub printArrays() Dim i As Integer picOutput.Cls picOutput.Print "First Name"; Tab(20); "Last Name"; Tab(40); "Phone" For i = 1 To intRecCount picOutput.Print strFirstNamesArray(i); Tab(20); strLastNamesArray(i); Tab(40); strPhoneNumArray(i) Next i End Sub Public Sub printSingleRecord() Dim i As Integer intSingleRecCount = intSingleRecCount + 1 If intSingleRecCount > intRecCount Then intSingleRecCount = 1 picOutput.Cls picOutput.Print "First Name"; Tab(20); "Last Name"; Tab(40); "Phone" picOutput.Print strFirstNamesArray(intSingleRecCount); Tab(20); strLastNamesArray(intSingleRecCount); Tab(40); strPhoneNumArray(intSingleRecCount) End Sub Private Sub Form_Activate() Call cmdSortList_Click End Sub