0

需要一些帮助来完成这个程序,一切都像我想要的那样工作和运行,但我需要显示一个输入框,允许用户输入他们想要存储在 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
4

1 回答 1

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
于 2012-10-05T05:52:19.370 回答