Results 1 to 8 of 8

Thread: ranking textboxes

Threaded View

  1. #7
    Hyperactive Member Vexslasher's Avatar
    Join Date
    Feb 2010
    Posts
    429

    Re: ranking textboxes

    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:
    1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    2.         Dim lb As New ListBox
    3.         Dim Ascendinglb As New List(Of Double)
    4.         Dim ItemToAdd As Double
    5.         For i As Integer = 1 To 5
    6.             Dim tb = Me.Controls("TextBox" & i)
    7.             If Double.TryParse(tb.Text, ItemToAdd) Then
    8.                 lb.Items.Add(ItemToAdd)
    9.                 tb.Text = ""
    10.             End If
    11.         Next
    12.         If lb.Items.Count > 1 Then
    13.             Ascendinglb.Clear()
    14.             For i = 0 To lb.Items.Count - 1
    15.                 Ascendinglb.Add(CDbl(lb.Items(i)))
    16.             Next
    17.             Ascendinglb.Sort()
    18.             lb.Items.Clear()
    19.             For i = 0 To Ascendinglb.Count - 1
    20.                 Dim tb = Me.Controls("TextBox" & i + 1)
    21.                 tb.Text = Ascendinglb(i).ToString
    22.                 'or you could add them to a listbox sorted like this
    23.                 'ListBox1.Items.Add(Ascendinglb(i))
    24.             Next
    25.         End If
    26.     End Sub
    Last edited by Vexslasher; Nov 30th, 2016 at 04:14 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width