Results 1 to 8 of 8

Thread: ranking textboxes

Threaded View

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

    Re: ranking textboxes

    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:
    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 Integer)
    4.         Dim ItemToAdd As Integer
    5.         For i As Integer = 1 To 5
    6.             Dim tb = Me.Controls("TextBox" & i)
    7.             If Integer.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(CInt(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.             Next
    23.         End If
    24.     End Sub
    Last edited by Vexslasher; Nov 28th, 2016 at 07:13 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