比较 vb.net 中的日期的过程似乎没有做任何事情
Procedure comparing dates in vb.net doesn't appear to do anything
几乎就是标题,我一直在学习 vb 我的计算机科学 A-level 和 运行 在这个练习中遇到了一些麻烦。我做了一个程序通过比较当前日期和到期日来影响发票的最终成本,但我输入的到期日似乎对最终成本没有任何影响。
表格:
Invoice Form
任务:
Write a program that processes invoices for a company selling a variety of products. Ask the user to enter the unit cost of the product, how many were sold and the date the invoice had to be paid by. A check box should be used to indicate if the product is VAT rated. When these details have been entered the user should click a button. This event should call two general procedures. The first should calculate and return the basic cost of the invoice, including VAT. The second should reduce the basic cost by 10% if the invoice has been paid on time. The final cost should be displayed by the Click event of the button.
代码:
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
问题说“这个事件应该调用两个通用过程。第一个应该计算和 return...” - 注意它说“return” - 这意味着它需要函数,而不是子函数。
修复后,发票值可以在参数中从一种方法传递到另一种方法,因此您可以从它所在的位置删除 Dim invoice As Integer
,因为它当前的范围是整个 class,你可能不想要。
此外,invoice
应该是小数,而不是整数。
几乎就是标题,我一直在学习 vb 我的计算机科学 A-level 和 运行 在这个练习中遇到了一些麻烦。我做了一个程序通过比较当前日期和到期日来影响发票的最终成本,但我输入的到期日似乎对最终成本没有任何影响。
表格:
Invoice Form
任务:
Write a program that processes invoices for a company selling a variety of products. Ask the user to enter the unit cost of the product, how many were sold and the date the invoice had to be paid by. A check box should be used to indicate if the product is VAT rated. When these details have been entered the user should click a button. This event should call two general procedures. The first should calculate and return the basic cost of the invoice, including VAT. The second should reduce the basic cost by 10% if the invoice has been paid on time. The final cost should be displayed by the Click event of the button.
代码:
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
问题说“这个事件应该调用两个通用过程。第一个应该计算和 return...” - 注意它说“return” - 这意味着它需要函数,而不是子函数。
修复后,发票值可以在参数中从一种方法传递到另一种方法,因此您可以从它所在的位置删除 Dim invoice As Integer
,因为它当前的范围是整个 class,你可能不想要。
此外,invoice
应该是小数,而不是整数。