' This program required you to create a form containing ' a single text box, txtOutput, which must have Multiline ' set to True ' This code should be in your main form's source file ' (e.g. frmMain.frm) Option Explicit Dim strName(50) As String Dim blankpos As Single Dim a As Single Dim strLast(50) As String Dim strFirst(50) As String Dim strTemp As String Dim flag As Boolean Dim i As Integer Dim l As Integer Private Sub Form_Load() Open "test.dat" For Input As #1 Do While Not EOF(1) ' read each line from file a = a + 1 Line Input #1, strName(a) ' get the first name and the last name blankpos = InStr(1, strName(a), " ") strLast(a) = Mid(strName(a), 1, blankpos - 1) strFirst(a) = Mid(strName(a), blankpos + 1, Len(strName(a))) Loop Close #1 ' now sort the names by last name For i = 1 To a For l = a To 1 Step -1 If strLast(l) > strLast(l + 1) Then ' swap the last names strTemp = strLast(l) strLast(l) = strLast(l + 1) strLast(l + 1) = strTemp ' swap the first names strTemp = strFirst(l) strFirst(l) = strFirst(l + 1) strFirst(l + 1) = strTemp End If Next l Next i ' print the names to the text box For l = 2 To a + 1 txtOutput.Text = txtOutput.Text & (strFirst(l) & " " & strLast(l)) & vbCrLf Next l End Sub