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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
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.
Last edited by jdelano; Jul 25th, 2024 at 05:17 AM.
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.....
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
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.
Last edited by jdelano; Jul 25th, 2024 at 07:10 AM.
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
Last edited by .paul.; Jul 25th, 2024 at 01:13 PM.