我是 VB 的新手,对于一个课堂项目,我们将制作一个更改计算器,类似于之前在这里提出的问题。我有一个欠款和支付金额标签和文本框。如果拥有的金额大于支付的金额,程序应该显示消息提醒客户并告诉他们还需要支付多少。
我想通了,但消息中显示的到期金额为-1。
示例:欠款:25 已付金额:10 消息将显示,已付金额少于欠款。请多付$-1。
我不确定我做错了什么,我被卡住了。任何帮助将不胜感激!
Option Strict On
Option Explicit On
Public Class Form1
Dim AmountPaid As Double
Dim AmountOwed As Double
Private Sub CalculateButton_Click(sender As Object, e As EventArgs) Handles CalculateButton.Click
'input amount owed from OwedMaskedTextBox
'input paid amount from PaidTextBox
AmountOwed = Convert.ToDouble(OwedTextBox.Text)
AmountPaid = Convert.ToDouble(PaidTextBox.Text)
'calculate difference of amount owed and paid
'display an alert message if paid amount is less than what is owed
Dim dif As Double
Dim result As Double = 0
result = CDbl(AmountPaid < AmountOwed)
dif = AmountPaid - AmountOwed
If CBool(result) Then
AlertLabel.Text = "Amount paid is less than what is owed." &
"Please pay $ " & result & " more."
Else
AlertLabel.Text = ""
End If
'display the result
'let totallabel change text to display the difference
TotalLabel.Text = "Change: " &
dif.ToString()
End Sub
End Class