用日期到日期 vb.net 的每一天填充列表框
fill list box with each day from date to date vb.net
我想在列表框中添加从 2014 年 1 月 1 日开始直到有人加载我的表单的日期,如下所示:
1/Jan/2014
2/Jan/2014
3/Jan/2014
..
..
..
今天的日期
谢谢
是这样的吗?
Public Sub Form_Load()
FillList()
End Sub
Private Sub FillList()
Dim dWorkDate As Date = CDate("01.01.2014")
While dWorkDate < Date.Today
myListBox.Items.Add(dWorkDate.ToString("dd.MM.yyyy"))
dWorkDate = dWorkDate.AddDays(1)
End While
End Sub
假设:
- 您的表格名称是
Form1
- 您有一个名为
ComboBox1
的组合框控件(您可以将其更改为列表框,但我建议使用组合框以便于使用和显示)
这些是当您在其中插入表单和控件时 VB 给出的默认名称。只需将子内容复制粘贴到 Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim D As Date
Dim TD As Date
Dim Count As Integer
TD = FormatDateTime(Today, DateFormat.GeneralDate)
D = #1/1/2014#
ComboBox1.Items.Add(FormatDateTime(D, DateFormat.GeneralDate).ToString)
Count = DateDiff(DateInterval.Day, D, TD)
For i As Integer = 0 To Count - 1
D = D.AddDays(1)
ComboBox2.Items.Add(FormatDateTime(D, DateFormat.GeneralDate).ToString)
Next
End Sub
输出:
我想在列表框中添加从 2014 年 1 月 1 日开始直到有人加载我的表单的日期,如下所示:
1/Jan/2014
2/Jan/2014
3/Jan/2014
..
..
..
今天的日期
谢谢
是这样的吗?
Public Sub Form_Load()
FillList()
End Sub
Private Sub FillList()
Dim dWorkDate As Date = CDate("01.01.2014")
While dWorkDate < Date.Today
myListBox.Items.Add(dWorkDate.ToString("dd.MM.yyyy"))
dWorkDate = dWorkDate.AddDays(1)
End While
End Sub
假设:
- 您的表格名称是
Form1
- 您有一个名为
ComboBox1
的组合框控件(您可以将其更改为列表框,但我建议使用组合框以便于使用和显示)
这些是当您在其中插入表单和控件时 VB 给出的默认名称。只需将子内容复制粘贴到 Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim D As Date
Dim TD As Date
Dim Count As Integer
TD = FormatDateTime(Today, DateFormat.GeneralDate)
D = #1/1/2014#
ComboBox1.Items.Add(FormatDateTime(D, DateFormat.GeneralDate).ToString)
Count = DateDiff(DateInterval.Day, D, TD)
For i As Integer = 0 To Count - 1
D = D.AddDays(1)
ComboBox2.Items.Add(FormatDateTime(D, DateFormat.GeneralDate).ToString)
Next
End Sub
输出: