私はレジのウィンドウフォーム(下の写真のようになります)を作成しようとしています。これを考えすぎていることはわかっていますが、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