You put your shoes on before your socks, and used underwear for a sock… Programming is all about order.
A program to get dressed might look like this:
underwear
socks
shirt
pants
belt
In your calculate button you need to:
validate input (optional)
determine input type (check, deposit, service charge)
add or subtract input from stored value (balance)
display stored value
In your comment 34702357 the order is more like:
declare variable (AmountDecimal)
determine input type (check, deposit, service charge)
add or subtract input from stored value (balance)
set stored value (balance) to input
display stored value
Won’t work in that order.
Fix and move this bit:
‘Convert input to decimal.
BalanceDecimal = Decimal.Parse(AmountTextBox.Text)
Fix:
‘Convert input to decimal.
AmountDecimal = Decimal.Parse(AmountTextBox.Text)
Move above:
‘Calculate and display the current amounts and add to totals.
Like this:
Public Class CheckingAccountBalance
‘Declare module-level variable for summary of balance.
Private BalanceDecimal As Decimal
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
‘Declare local-level variable.
Dim AmountDecimal As Decimal
‘Convert input to decimal.
AmountDecimal = Decimal.Parse(AmountTextBox.Text)
‘Calculate and display the current amounts and add to totals.
‘If statement
If DepositRadioButton.Checked Then
BalanceDecimal = BalanceDecimal + AmountDecimal
ElseIf CheckRadioButton.Checked Then
BalanceDecimal = BalanceDecimal – AmountDecimal
ElseIf ServiceChargeRadioButton.Checked Then
BalanceDecimal = BalanceDecimal – AmountDecimal
End If
‘Format and display balance output.
BalanceTextBox.Text = BalanceDecimal.ToString(“C“)
End Sub


0 comments