如何在visual basic中添加两个datetimepicker并在文本框中显示

时间:2015-05-21 06:37:09

标签: vb.net visual-studio-2013

我需要我的项目。如果放在消息框上,它将起作用并显示多少天,但是如果在文本框中不起作用。

If True Then
    Dim dt1 As DateTime = Convert.ToDateTime(DateTimePicker1.Text)
    Dim dt2 As DateTime = Convert.ToDateTime(DateTimePicker2.Text)
    Dim ts As TimeSpan = dt2.Subtract(dt1)

    If Convert.ToInt32(ts.Days) >= 0 Then
        MessageBox.Show("Total Days are " & Convert.ToInt32(ts.Days))
    Else
        MessageBox.Show("Invalid Input")
    End If
End If

1 个答案:

答案 0 :(得分:0)

我不知道这不会起作用......如果它没有向我们提供你得到的错误

If True Then
    Dim dt1 As DateTime = DateTimePicker1.Value
    Dim dt2 As DateTime = DateTimePicker2.Value
    Dim ts As TimeSpan = dt2.Subtract(dt1)

    If ts.Days >= 0 Then
        TextBox1.Text = ts.Days
    Else
        TextBox1.Text = "Invalid Input"
    End If
End If