' sorts the array of cd structures based on inventory (high to low)

    Private Sub sortStructByInventory(ByRef array() As cd, ByVal num As Integer)

        Dim outer As Integer

        Dim inner As Integer

        Dim posOfLarge As Integer

        Dim temp As cd

        ' loop through all but last position of the array

        ' each time, place the largest remaining inventory into the current position

        For outer = 0 To (num - 2)

            posOfLarge = outer    ' default to largest being first

            ' loop through remaining cds finding the largest inventory

            For inner = outer + 1 To (num - 1)

                If array(inner).inventory > array(posOfLarge).inventory Then

                    ' new largest - update position of largest

                    posOfLarge = inner

                End If

            Next inner

            ' determine if a swap is needed

            If posOfLarge <> outer Then

                temp = array(posOfLarge)

                array(posOfLarge) = array(outer)

                array(outer) = temp

            End If

        Next outer

    End Sub