幾乎只是標題,我一直在為我的計算機科學 A-level 學習 vb,但在這個練習中遇到了一些麻煩。我通過將當前日期與到期日進行比較來制定影響發票最終成本的程式,但我輸入的到期日似乎對最終成本沒有任何影響。
形式:
發票表格
任務:
為一家銷售各種產品的公司撰寫一個處理發票的程式。要求用戶輸入產品的單位成本、售出數量以及必須支付發票的日期。應使用復選框來指示產品是否為增值稅稅率。輸入這些詳細資訊后,用戶應單擊按鈕。這個事件應該呼叫兩個通用程序。首先應計算并回傳發票的基本成本,包括增值稅。如果發票已按時支付,第二個應將基本成本降低 10%。最終成本應由按鈕的 Click 事件顯示。
代碼:
Public Class Form1
Dim invoice As Integer
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim unitCost As Integer = txtCost.Text 'Input cost of product in textbox
Dim unitsSold As Integer = txtUnits.Text 'Input units sold in textbox
Dim dueDate As Date = dtpDueDate.Value 'Input date in date and time picker
Dim VATCheck As Boolean = chkVAT.Checked 'Input VAT rating in checkbox
Call InvoiceProcess(unitCost, unitsSold, VATCheck)
Call DueCheck(dueDate, invoice)
MsgBox(invoice)
End Sub
Sub InvoiceProcess(ByRef price As Integer, ByRef units As Integer, ByRef VAT As Boolean)
If VAT = True Then
invoice = 1.2 * price * units
Else
invoice = price * units
End If
End Sub
Sub DueCheck(ByRef dateDue As Date, ByVal invoice As Integer)
Dim todayDate As Date = Today.Date 'Current date
Dim overDue As Integer = DateTime.Compare(todayDate, dateDue.Date)
If overDue <= 0 Then
invoice = invoice * 0.9
End If
End Sub
End Class
uj5u.com熱心網友回復:
問題是“這個事件應該呼叫兩個通用程序。第一個應該計算并回傳......” - 注意它說“return” - 這意味著它需要是一個函式,而不是一個子程式。
一旦你解決了這個問題,發票值就可以在引數中從一個方法傳遞到另一個方法,因此你可以Dim invoice As Integer
從它所在的位置洗掉它,因為它當前的范圍是整個類,你可能不想要。
此外,invoice
應該是小數,而不是整數。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/426190.html