This should do the trick you will have to modify it slightly to work with the names you have set your textboxes to though, I just did it this way to save me some time so I wouldn't have to repeat the same code a few times for those 5 textboxes.
vb.net Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim lb As New ListBox Dim Ascendinglb As New List(Of Integer) Dim ItemToAdd As Integer For i As Integer = 1 To 5 Dim tb = Me.Controls("TextBox" & i) If Integer.TryParse(tb.Text, ItemToAdd) Then lb.Items.Add(ItemToAdd) tb.Text = "" End If Next If lb.Items.Count > 1 Then Ascendinglb.Clear() For i = 0 To lb.Items.Count - 1 Ascendinglb.Add(CInt(lb.Items(i))) Next Ascendinglb.Sort() lb.Items.Clear() For i = 0 To Ascendinglb.Count - 1 Dim tb = Me.Controls("TextBox" & i + 1) tb.Text = Ascendinglb(i).ToString Next End If End Sub





Reply With Quote
