2012-10-05 67 views
0

需要一些幫助完成這個程序,一切正常,並運行像我想要的,但我需要顯示一個輸入框,允許用戶輸入他們希望的發票日期service_date存儲然後這個日期將顯示在列表框中,其中包含所有其他項目。我知道我需要使用AddDays函數,但我不知道如何去做,而在線研究讓我知道其他100件事情並非如此。在vb.net使用AddDays功能

因此,這裏是我的代碼:

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 
+0

爲什麼不使用的DateTimePicker? – SSS

+0

因爲用戶必須輸入它。我想過把它放在輸入框中......會在輸入框中工作嗎?用戶在單擊表單上的按鈕時會收到提示。 – compucrazy

回答

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 
+0

這是完美的。非常感謝! – compucrazy

+1

不客氣。如果有幫助,我會很感激你接受我的答案。乾杯,快樂的編程! – SSS

+0

如果用戶輸入日期爲10-5-2012,該怎麼辦? –