Insertion Sort Code

Below is a VB.NET implementation of an insertion sort.

Public Class Form1
 
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim aData(9) As Integer
        aData(0) = 8
        aData(1) = 5
        aData(2) = 3
        aData(3) = 12
        aData(4) = 9
        aData(5) = 2
        aData(6) = 34
        aData(7) = 24
        aData(8) = 16
        aData(9) = 1
 
        Call InsertionSort(aData)
 
        Dim stOut As String
        For i As Integer = 0 To 9
            stOut = stOut & aData(i) & vbNewLine
        Next
        MsgBox(stOut)
    End Sub
 
    Sub InsertionSort(aData As Array)
        Dim i As Integer, iTemp As Integer
        For i = 1 To UBound(aData)
            Do While (i > 0)
                If aData(i) > aData(i - 1) Then
                    Exit Do
                End If
                iTemp = aData(i)
                aData(i) = aData(i - 1)
                aData(i - 1) = iTemp
                i = i - 1
            Loop
        Next
    End Sub
 
End Class