Public Class Form1 'Created by Zeki Ozyilmaz for CST112 Professor: BAM ' -----////\\\\----- ' ------| Ozzy |------ ' -----\\\\////----- Dim many As Integer = 5 Dim id() As Integer = {0, 214642, 123121, 321123, 419642, 419643} Dim ln() As String = {" ", "Johnson", "Servrino", "Brandon", "Ozyilmaz", "Christian"} Dim fn() As String = {" ", "Chris", "Mark", "Joe", "Ozzy", "Emily"} Dim rates() As String = {" ", "10.52", "7.25", "14.00", "12.35", "11.12"} Private Sub Bdisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bdisplay.Click outputsort() 'displays original/last used sort End Sub Private Sub BLastname_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BLastname.Click sortname(ln, many) 'sorts arrays by last name outputsort() End Sub Private Sub Bidnum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bidnum.Click sortid(id, many) 'sorts arrays by the person's "id number" outputsort() End Sub Private Sub BFirstname_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BFirstname.Click sortname(fn, many) 'sorts arrays by first name outputsort() End Sub Private Sub BPayrate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BPayrate.Click sortname(rates, many) 'sorts arrays by payrate outputsort() End Sub Sub sortid(ByRef a() As Integer, ByVal m As Integer) 'bubble sort of the arrays Dim ok = True Do ok = True For i = 1 To (m - 1) If (a(i) > a(i + 1)) Then Call swapall(i, i + 1) 'swaps ok = False End If Next i Loop Until (ok) End Sub Sub outputsort() 'Outputs the arrays, it does not need input due to global declarations of the arrays Dim fmtstr As String = "{0,-10}{1,12}{2,14}{3,12}" With lOutput.Items .Clear() .Add(String.Format(fmtstr, "id", "lastname", "firstname", "payrate")) For j = 1 To many .Add(String.Format(fmtstr, id(j), ln(j), fn(j), rates(j))) Next End With End Sub Sub swapall(ByVal j As Integer, ByVal k As Integer) 'swap all arrays swapint(id, j, k) swapstring(ln, j, k) swapstring(fn, j, k) swapstring(rates, j, k) End Sub Sub swapint(ByRef a() As Integer, ByVal j As Integer, ByVal k As Integer) 'swap (exchanges places in array) Dim save As Integer save = a(j) a(j) = a(k) a(k) = save End Sub Sub swapstring(ByRef a() As String, ByVal j As Integer, ByVal k As Integer) 'swap (exchanges places in array) Dim save As String save = a(j) a(j) = a(k) a(k) = save End Sub Sub sortname(ByRef a() As String, ByVal m As Integer) 'bubble sort Dim ok = True Do ok = True For i = 1 To (m - 1) If (a(i) > a(i + 1)) Then Call swapall(i, i + 1) 'swaps ok = False End If Next i Loop Until (ok) End Sub End Class