에 "지불 한 금액"이 충분하지 않습니다. 저는 VB를 처음 사용하고 있으며, 클래스 프로젝트의 경우 이전에 질문 한 것과 비슷한 변경 계산기를 만들어야합니다. 나는 빚진 금액과 금액을 지불 한 라벨과 텍스트 박스를 가지고있다. 소유 한 금액이 지불 한 금액보다 많으면 프로그램에 고객에게 상기시키고 지불 할 금액을 알려주는 메시지가 표시되어야합니다.변경 계산기, VB VS2012
나는 알아 냈지만 메시지에 여전히 표시되는 금액은 -1입니다.
예 : 빚 금액 : 유료 25 금액 : 메시지는 읽을 수 10 , 지불 금액이 빚진 것보다 작습니다. $ -1 더 지불하십시오.
내가 잘못했는지 잘 모르겠다. 어떤 도움을 주시면 감사하겠습니다! 이 방법
'calculate difference of amount owed and paid
'display an alert message if paid amount is less than what is owed
Dim result As Boolean
result = (AmountPaid < AmountOwed)
dif = AmountPaid - AmountOwed
If result Then
.....
표현 (AmountPaid < AmountOwed)
에서
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