# Thread: [RESOLVED] How to rank 5 textbox value to another 5 textbox?

1. ## [RESOLVED] How to rank 5 textbox value to another 5 textbox?

Hello,

I want to rank my 5 textbox data to another 5 textbox. For example I have 5 data in my Five text box.

TextBox1.text = 10
TextBox2.text= 12
TextBox3.text= 9
TextBox4.text=15
TextBox5.text=21

I want to put this five textbox data to another five textbox (highest value to lowest value.

Is it possible? And how?

Thanks

2. ## Re: How to rank 5 textbox value to another 5 textbox?

Throw the values of your first 5 textboxes into an Array, sort the Array, then assign the sorted Array-Values to your second 5 Textboxes going backwards through the Array

3. ## Re: How to rank 5 textbox value to another 5 textbox?

You could put the values in an array and use Reverse(), you need to import System.Array (edit 2: fixed typo)

Here is an example:
Code:
```    Dim sortArray() As Int16 = {10, 12, 9, 15, 21}
Dim displayResults As String = ""

'Sort(sortArray)
Reverse(sortArray)

For Each i As Int16 In sortArray
displayResults += i.ToString & ","
Next

MsgBox(\$"Array sorted is {displayResults}")```
have to switch browsers to upload a screenshot, Edge is not working EDIT: added screenshot

edit: use the Reverse function.

4. ## Re: How to rank 5 textbox value to another 5 textbox?

Originally Posted by jdelano
You could put the values in an array and use Sort(), you need to import System.Array (edit 2: fixed typo)

Here is an example:
Code:
```    Dim sortArray() As Int16 = {10, 12, 9, 15, 21}
Dim displayResults As String = ""

Sort(sortArray)

For Each i As Int16 In sortArray
displayResults += i.ToString & ","
Next

MsgBox(\$"Array sorted is {displayResults}")```
have to switch browsers to upload a screenshot, Edge is not working EDIT: added screenshot
OP wants highest Value first.....

5. ## Re: How to rank 5 textbox value to another 5 textbox?

Originally Posted by Zvoni
OP wants highest Value first.....
Uhg what a bonehead I am.

6. ## Re: How to rank 5 textbox value to another 5 textbox?

Originally Posted by jdelano
Uhg what a bonehead I am.
You do realize, that your Screenshot is not SORTED?

EDIT: And let's not forget, that those values are in textboxes, wich would make them Strings, so assigning those Values to an Integer-Array would ne a TypeCast

7. ## Re: How to rank 5 textbox value to another 5 textbox?

Originally Posted by Zvoni
You do realize, that your Screenshot is not SORTED?

EDIT: And let's not forget, that those values are in textboxes, wich would make them Strings, so assigning those Values to an Integer-Array would ne a TypeCast
Goooodd grief ... I'm going back to bed and starting today over. (egg faced loser - out)

EDIT: okay LAST time
In order to sort the numbers properly they need to be an integer, so add them to an array like

using this code:
Code:
```    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sortArray(4) As Int16
Dim displayResults As String = ""
Dim textboxIndex As Integer
Dim txtBox As TextBox

For textboxIndex = 1 To 5
' find each textbox and get the value entered
txtBox = CType(Me.Controls.Find("TextBox" & textboxIndex.ToString(), True)(0), TextBox)

' add the value to the array
sortArray(textboxIndex - 1) = Convert.ToInt16(txtBox.Text)
Next textboxIndex

Sort(sortArray)
Reverse(sortArray)

For Each i As Int16 In sortArray
displayResults += i.ToString & ","
Next

MsgBox(\$"Array sorted is {displayResults}")

End Sub```
I'm going to find a rock to hide under now.

You'll need to test for whether an actual number is in the textbox, you can then use a second for loop to write the array to the second set of 5 textboxes (presumably TextBox6, 7, 8, 9, 10) in much the same way the first loop finds the first 5.

8. ## Re: How to rank 5 textbox value to another 5 textbox?

Attachment 192362

thank you but I want to transfer 5 textbox data to another5 textbox.

9. ## Re: How to rank 5 textbox value to another 5 textbox?

Attachment 192363

Attachment 192362

thank you but I want to transfer 5 textbox data to another5 textbox. like the image.

10. ## Re: How to rank 5 textbox value to another 5 textbox?

Use the for loop I used to read the first 5 textboxes as an example to write to the other 5 textboxes.

11. ## Re: How to rank 5 textbox value to another 5 textbox?

Sorry to say I am new in VB. Can you help me to write the code? Please.

12. ## Re: How to rank 5 textbox value to another 5 textbox?

Code:
```Dim inputTextBoxes() As TextBox = {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5}
Dim values(4) As Integer

For x As Integer =0 To 4
Dim v As Integer
Integer.TryParse(inputTextBoxes(x).Text, v)
values(x) = v
Next

Array.Sort(values)
Array.Reverse(values)

Dim outputTextBoxes() As TextBox = {TextBox6, TextBox7, TextBox8, TextBox9, TextBox10}

For x As Integer =0 To 4
outputTextBoxes(x).Text = values(x).ToString
Next```

13. ## Re: How to rank 5 textbox value to another 5 textbox?

Thank you so much.

#### 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