I would like to create an alphabetic sorter on Vb. I want the user to be able to type things into a textbox and then sort them alphabetically in another label. I am not fully sure how to do this.
Asked
Active
Viewed 75 times
-1
-
What did you have tried so far? – robni Jun 22 '22 at 21:11
-
I tried watching a video that told me to use arrays but didn't allow the user to type in their own words. – Anpnymous 101 Jun 22 '22 at 23:11
1 Answers
1
The List type has a useful subroutine called Sort that will sort your List either by a default sorting order or with a custom one. Or sort with lambda.
Module Module1
Sub Main()
Dim l As List(Of String) = New List(Of String)
l.Add("mississippi")
l.Add("indus")
l.Add("danube")
l.Add("nile")
' Sort using lambda expression.
l.Sort(Function(elementA As String, elementB As String)
Return elementA.Length.CompareTo(elementB.Length)
End Function)
For Each element As String In l
Console.WriteLine(element)
Next
End Sub
End Module

Prof.
- 11
- 2