Oh I'm sorry I did integers instead of doubles here I changed them for you it should work with those types of numbers like you provided now. I'm sorry I didn't notice my error sooner.
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 Double) Dim ItemToAdd As Double For i As Integer = 1 To 5 Dim tb = Me.Controls("TextBox" & i) If Double.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(CDbl(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 'or you could add them to a listbox sorted like this 'ListBox1.Items.Add(Ascendinglb(i)) Next End If End Sub





Reply With Quote
