# Microsoft Visual Studio 2010 Help



## tmprather (May 16, 2011)

We were given an assignment to create a program that computes your Checking Account Balance. You include radio buttons to indicate the type of transaction: deposit, check, or service charge. Use text box to allow the user to enter the amount of the transaction. Display new balance in a ReadOnly Text box. Add validation by displaying a message box if the new balance would be a negative number. If there is not enough money to cover a check, do not deduct the check amount. Instead, display a message box with the message "Insufficient Funds" and deduct a service charge of $10.


```
Public Class Form1
    'Define modular level variables

    Dim CheckDecimal As Decimal
    Dim DepositDecimal As Decimal
    Dim ServiceFeeDecimal As Decimal
    Const SERVICE_CHG_DECIMAL As Decimal = 10
    Dim BalanceDecimal As Decimal
    Dim TotalDepositdecimal As Decimal

    Private Sub Calculate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click

        'Define local variables

        Dim AmountDecimal As Decimal

        Try ' Calculate the balance for deposits, checks, and service charges

            Amountdecimal = Decimal.Parse(AmountTextBox.Text)

            If DepositRadioButton.Checked Then
                ' Deposits
                Depositdecimal = Amountdecimal
                BalanceDecimal += Depositdecimal
                TotalDepositdecimal += Depositdecimal
                BalanceTextBox.Text = BalanceDecimal.ToString("c")

            End If

            If CheckRadioButton.Checked Then
                'Checks/Insufficient Funds
                Checkdecimal = Amountdecimal

            End If

            If BalanceDecimal < Amountdecimal Then

                MessageBox.Show("Insufficient Funds", "USA Bank Account", MessageBoxButtons.OK)

                BalanceDecimal -= SERVICE_CHG_DECIMAL
                Checkdecimal -= Amountdecimal
                BalanceTextBox.Text = BalanceDecimal.ToString()
                Amountdecimal = Decimal.Parse(AmountTextBox.Text)

            End If
        Catch Amountdecimalexception As FormatException

            If ServiceChgRadioButton.Checked Then
                'Service Charges
                ServiceFeeDecimal = Amountdecimal
                BalanceDecimal -= ServiceFeeDecimal
                BalanceTextBox.Text = BalanceDecimal.ToString()

            End If

        End Try

    End Sub

    Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click

        DepositRadioButton.Checked = False
        CheckRadioButton.Checked = False
        ServiceChgRadioButton.Checked = False
        InvisibleRadiobutton.Checked = True

        BalanceTextBox.Text = ""
        AmountTextBox.Text = ""

    End Sub

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
        Me.Close()

    End Sub
End Class
```









I cannot seem to figure out why the check or service charges wont calculate into the balance. Can someone please check to make sure that I did this ok, any suggestions.

Thank you


----------



## tmprather (May 16, 2011)

I think I figured it out, can someone please look at my code and make sure it looks about right...

Public Class Form1
'Define modular level variables

Dim CheckDecimal As Decimal
Dim DepositDecimal As Decimal
Dim ServiceFeeDecimal As Decimal
Const SERVICE_CHG_DECIMAL As Decimal = 10
Dim BalanceDecimal As Decimal
Dim TotalDepositdecimal As Decimal

Private Sub Calculate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click

'Define local variables

Dim AmountDecimal As Decimal

Try ' Calculate the balance for deposits, checks, and service charges

AmountDecimal = Decimal.Parse(AmountTextBox.Text)

If DepositRadioButton.Checked Then
' Deposits
DepositDecimal = AmountDecimal
BalanceDecimal += DepositDecimal
BalanceLabel.Text = BalanceDecimal.ToString("c")

End If

If CheckRadioButton.Checked Then
'Check clears
CheckDecimal -= AmountDecimal

End If

If BalanceDecimal < AmountDecimal Then
'Insufficient Funds Notice- check returned unpaid and customer chgd a $10.00 service fee
MessageBox.Show("Insufficient Funds", "North Bank", MessageBoxButtons.OK)

BalanceDecimal -= SERVICE_CHG_DECIMAL
BalanceLabel.Text = BalanceDecimal.ToString("c")
AmountDecimal = Decimal.Parse(AmountTextBox.Text)

End If

If ServiceChgRadioButton.Checked Then
'Service Charges
BalanceDecimal -= AmountDecimal
BalanceLabel.Text = BalanceDecimal.ToString("c")

End If
Catch Amountdecimalex As FormatException
'Catch customer failure

End Try

End Sub

Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click

DepositRadioButton.Checked = False
CheckRadioButton.Checked = False
ServiceChgRadioButton.Checked = False
InvisibleRadiobutton.Checked = True

BalanceLabel.Text = ""
AmountTextBox.Text = ""
BalanceDecimal = 0

End Sub

Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()

End Sub
End Class


----------



## Crockeo (Apr 17, 2010)

I regret to inform you that we are unable to help you with school projects, but might I say good luck, you're much better with Visual Basic than I am.


----------



## MstrPBK (May 25, 2011)

This is my first post here; I am within my first two weeks of relearning BASIC as a computer language; and my studies are being done independently of any classroom.

I have done some reading about the variable structure within VB. And the structure seems to be both pretty straight forward and at some levels intuitive. At the heart of my question are the variables V01 (V zero 1) through V10. They seem to be accepted as dimensioned variables, but not being accepted with in FOR NEXT loops. Could someone provide me with some insight as to what is happening?

Peter Kelley
St. Paul, MN USA


----------

