Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15589

Trying to sort a list into date order.

$
0
0
Hi,

I have functioning project which I'm trying to modify to display a list of times achieved, recorded with the relevant date, into date order.

The list already exists as a List of String, named 'times' currently with 28 items.
This is the method I thought I'd use:
Vb.net Code:
  1. Private Sub SortDate()
  2.         Dim txt As String
  3.         Dim count As Integer = times.Count - 1
  4.         Dim order As New SortedList(Of Date, String)
  5.  
  6.         For i = 0 To count
  7.             txt = Date.Parse(times(i).Substring(0, 12).Trim)
  8.             txt = txt.Substring(0, 8)
  9.             order.Add(txt & i.ToString, " " & times(i))
  10.         Next
  11.  
  12.         TextBox2.Clear()
  13.         For i = 0 To count
  14.             txt = order(i).Substring(10)
  15.             TextBox2.AppendText(txt & NewLine)
  16.         Next
I had to add the i.ToString in Line 9 to change the key names, after that all works up to line 12. Achieving 28 items in the 'order' list.

When I come to add lines 13 to 16, intellisense complains about the index in line 14:
Quote:

Severity Code Description Project File Line Suppression State
Error BC30311 Value of type 'Integer' cannot be converted to 'Date'. SudokuRecord D:\Visual Studio Projects\Projects\SudokuRecord\Form1.vb 111 Active
So clearly I'm not using the correct code to read the list.
I've tried adding the index to the line in the list that I'm trying to read but can't find how to do that.


Poppa

Viewing all articles
Browse latest Browse all 15589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>