troubleshooting Question

VB Net - Sort a Multi List that Contains Duplicates

Avatar of spen_lang
spen_lang asked on
Visual Basic.NETVB Script.NET ProgrammingSSRSMicrosoft Server OS
4 Comments1 Solution17 ViewsLast Modified:

I need add 6 values (3 rows) to a list and then sort the list by the datetime value. However, this value is not unique. I am then outputting the list to a string.

The following works well until I have duplicate values. How can I change the following to allow duplicates?

This is code that I am adding to a Reporting Services report.

Thanks, Greg

    Friend Function GetStatusHistory(sStatus1 As String, dtStatusTime1 As Nullable(Of DateTime), sStatus2 As String, dtStatusTime2 As Nullable(Of DateTime), sStatus3 As String, dtStatusTime3 As Nullable(Of DateTime)) As String

        Dim sResult As String = ""
        Dim lstStatus As New System.Collections.Generic.SortedList(Of DateTime, String)

        If Not IsNothing(dtStatusTime1) Then
            lstStatus.Add(dtStatusTime1, sStatus1)
        End If

        If Not IsNothing(dtStatusTime2) Then
            lstStatus.Add(dtStatusTime2, sStatus2)
        End If

        If Not IsNothing(dtStatusTime3) Then
            lstStatus.Add(dtStatusTime3, sStatus3)
        End If

        For Each pair As System.Collections.Generic.KeyValuePair(Of DateTime, String) In lstStatus
            If String.IsNullOrEmpty(sResult) Then
                sResult = pair.Value + " @ " + pair.Key.ToString("dd/MM/yy HH:mm")
                sResult = sResult + ", " + pair.Value + " @ " + pair.Key.ToString("dd/MM/yy HH:mm")
            End If

        Return sResult

    End Function

Open in new window

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros