Jul 5, 2012

VB Program - Ascending order

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label3.Text = ""
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Add(TextBox1.Text)
        TextBox1.Text = ""
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim i, j, temp As Integer
        Label3.Text = "Numbers in Ascending order"
        For i = 0 To ListBox1.Items.Count - 2
            For j = i + 1 To ListBox1.Items.Count - 1
                If CInt(ListBox1.Items(i)) > CInt(ListBox1.Items(j)) Then
                    temp = ListBox1.Items(i)
                    ListBox1.Items(i) = ListBox1.Items(j)
                    ListBox1.Items(j) = temp
                End If
            Next j
        Next i
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ListBox1.Items.Clear()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        End
    End Sub
End Class



No comments:

Post a Comment