我试图在多个日期之间循环以将它们存储在文本框中,我有代码但是当它根据此代码到达第二个日期时
CType(Me.Controls("txtDate" & (intCursor + 1).ToString()),
TextBox).Text = dteTarget.ToShortDateString()
它显示错误对象引用未设置为对象的实例 我知道该值不为null,因为当我替换
时CType(Me.Controls("txtDate" & (intCursor + 1).ToString()), TextBox).Text
txtDate2= dteTarget.ToShortDateString
它正确地给了我我的价值
'第一次约会
txtDate1.Text = MonthCalendar1.SelectionStart.ToShortDateString()
Dim intCursor As Integer = 1
'Keep adding days to the starting date until you've reached the end.
Do Until MonthCalendar1.SelectionStart.Date.AddDays((intCursor)) >= MonthCalendar1.SelectionEnd.Date
Dim dteTarget As Date = MonthCalendar1.SelectionStart.Date.AddDays((intCursor))
'Casts the Textbox using a naming convention: txtDate1, txtDate2, txtDate3, etc.
CType(Me.Controls("txtDate" & (intCursor + 1).ToString()), TextBox).Text = dteTarget.ToShortDateString()
intCursor += 1
Loop
'If the end date is not the same as the start date then add that.
If MonthCalendar1.SelectionEnd.Date <> MonthCalendar1.SelectionStart.Date Then
CType(Me.Controls("txtDate" & (intCursor + 1).ToString()), TextBox).Text = MonthCalendar1.SelectionEnd.Date.ToShortDateString()
End If