我正在编写简单的程序来获取排序日期。但它不起作用。
Dim filepath As String = FileStr
Dim directoryPath As String = System.IO.Path.GetDirectoryName(filepath)
for Each file As String In System.IO.Directory.GetFiles(directoryPath)
Dates = {
Date.Parse(System.IO.Path.GetFileNameWithoutExtension(file))
}.ToList
Next
Dates.Sort()
ComboBox1.DataSource = Dates
它只显示一个日期..其中有超过10个日期。并且循环正在工作
我将List声明为全局
答案 0 :(得分:1)
您在每个循环中替换列表内容
Dim filepath As String = FileStr
Dim directoryPath As String = System.IO.Path.GetDirectoryName(filepath)
for Each file As String In System.IO.Directory.GetFiles(directoryPath)
Dates.Add(Date.Parse(System.IO.Path.GetFileNameWithoutExtension(file)))
Next
Dates.Sort(AddressOf SortDate)
ComboBox1.DataSource = Dates
更新:排序问题
然后作为单独的函数添加:
Function SortDate(ByVal a As DateTime, ByVal b As DateTime)
Dim result As Integer = a.Year.CompareTo(b.Year)
If result = 0 Then
a.Month.CompareTo(b.Month)
If result = 0 Then
a.Day.CompareTo(b.Day)
End If
End If
Return result
End Function
答案 1 :(得分:0)
您的循环每次都会替换$a = urldecode($this->uri->segment(3));
$b = $this->uri->segment(4);
$c = $this->uri->segment(5);
的值,因此您只能获得一个日期。
像这样改变循环:
Dates