我正在尝试制作一个收银机窗口表单(如下图所示),我知道我想多了,但我对 vb 真的很陌生,真的被这一切弄糊涂了。但它只需要加减余额。我需要帮助弄清楚如何在这里进行数学运算,例如由于用户将输入所有值,我们如何预期他们将在代码中输入什么?
这是我到目前为止所拥有的:
Public Class frmCashRegister
Dim Total As Decimal
Dim Subtract As Decimal
Dim Balance As Decimal
Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
txtBalance.Text = FormatCurrency(Val(txtAmount.Text))
End Sub
Private Sub txtBalance_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtBalance.TextChanged
If (txtBalance.Text < 0) Then
MsgBox("Transaction resulted in negative balance, please try again!")
End If
End Sub
Private Sub txtAmount_KeyPress(sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAmount.KeyPress
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
End Sub
End Class