I am working on coding a relational database in VisualBasics. I am stuck on sort
ID: 3771790 • Letter: I
Question
I am working on coding a relational database in VisualBasics. I am stuck on sorting the structures by the different strings and adding new structures on top of the existing one.
I have a the structure:
Private Structure UserInfo
Implements IComparable
Dim userName As String
Dim userPassword As String
Dim userDOB As String
Dim userAge As String
Dim userGender As String
Private Function IComparable_CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
Return userName.CompareTo(CType(obj, UserInfo). userName)
End Function
End Structure
I want the functions to sort by each string depending on which button I press and an example of how to use it. I’m having a difficult time with this because the current function I have will only work for one string and will give me errors if I try to write more than one function within the structure.
Again, please write this in Visual Basics.
Explanation / Answer
USE BELOW LINQ QUERIES TO SORT THE STRINGS. Add it in your button code as per the functionality. Dim sortStrUserName() As String = userName.OrderBy(Function(x) x).ToArray Dim sortStrUserPwd() As String = userPassword.OrderBy(Function(x) x).ToArray Dim sortStruserDOB() As String = userDOB.OrderBy(Function(x) x).ToArray Dim sortStruserAge() As String = userAge.OrderBy(Function(x) x).ToArray
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.