在vb.net中使用AddDays函数

时间:2012-10-05 05:16:34

标签: vb.net datetime

需要一些帮助来完成这个程序,一切正常并且像我想要的那样运行但我需要显示一个输入框,允许用户输入他们想要的发票存储在service_date中的日期,然后这个日期将显示在列表框中包含我放在那里的所有其他项目。我知道我需要使用AddDays函数,但我不知道如何做到这一点,并且在线研究只是让我发现了100个不是那样的东西。

所以这是我的代码:

 Dim Customer As String
Dim Phone As String
Dim Hours As Double
Dim Parts As Double
Dim due_date As String
Dim service_date As String

Private Sub cmdInputBox_Click()

    Dim service_date = InputBox("Enter the date of service. (MM/DD?YYYY)")
    MsgBox("That's your date, " & service_date.ToString)
    Exit Sub
End Sub

Private Sub CustInfo_Click()

    Customer = txtCustomer.Text
    Phone = mtbPhone.Text

    Double.TryParse(txtHours.Text, Hours)
    Double.TryParse(txtParts.Text, Parts)

    If Customer.Length < 0 Then
        MessageBox.Show("Please enter customer information.")
    End If

    If Phone = "" Then
        MessageBox.Show("Please enter phone number.")
    End If

    If Not Double.TryParse(txtHours.Text, Hours) Then
        MessageBox.Show("Please enter labor hours.")
    End If

    If Not Double.TryParse(txtParts.Text, Parts) Then
        MessageBox.Show("Please enter parts and supplies.")
    End If

    ''Perform calculations

    Dim Total_Cost As Double
    Dim Labor_Cost As Double
    Dim Parts_Cost As Double

    Parts_Cost = (Parts * 0.5 * 2)
    Labor_Cost = (Hours * 35)
    Total_Cost = (Hours + Parts)


    Customer = txtCustomer.Text
    Phone = mtbPhone.Text

    lstBill.Items.Clear()
    lstBill.Items.Add("Customer: " & vbTab & Customer.ToUpper)
    lstBill.Items.Add("Phone: " & vbTab & vbTab & Phone)
    lstBill.Items.Add("Service Date: " & vbTab & due_date)
    lstBill.Items.Add("Invoice Date: " & vbTab & service_date)
    lstBill.Items.Add("Labor Cost: " & vbTab & FormatCurrency(Labor_Cost))
    lstBill.Items.Add("Parts Cost: " & vbTab & FormatCurrency(Parts_Cost))
    lstBill.Items.Add("Total Cost: " & vbTab & FormatCurrency(Total_Cost))
    Exit Sub
End Sub

Private Sub btnBill_Click(sender As System.Object, e As System.EventArgs) Handles btnBill.Click

    cmdInputBox_Click()

    CustInfo_Click()

End Sub

1 个答案:

答案 0 :(得分:1)

试试这个:

Dim strDate As String = InputBox("Enter date?", , "")
If strDate = "" Then Exit Sub
Dim dteDate As Date
Dim enUS As New System.Globalization.CultureInfo("en-US")
If Date.TryParseExact(strDate, "MM/dd/yyyy", enUS, Globalization.DateTimeStyles.AssumeLocal, dteDate) Then
  MsgBox("Date is " & dteDate.ToString)
End If