Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Code the Calc button
as follows

a.
Dim var
iables for results of the Try/Parse and the calculations. Al
l the
numeric variables should be Decimal data type.
Dim the blnConverted
variable using Boolean data type.
b.
Try/Parse the contents of
each
text box to
a Decimal
variable.
If
blnConverted is false show an error in a messagebox, put the focus back
into the
text box, and exit the event. Repeat for each textbox.
c.
Compute the
Sub
total
(
Beginning Balance + Deposits

Withdrawals)
d.
Compute the Interest Earned. If the Subtotal is greater than 5000.00
the interest rate is 2 percent otherwise 1 percent.
e.
Compute
Endin
g Balance (Sub Total + Interest Earned)
f.
Display the
Interest Earned and Ending Balance
in label
s
and format
them
as currency.
4.
Test your coding of the Calc event before coding the rest of the events.
5.
Code the
keypress
event of the textboxes. Allow numbers, the backspace key,
and the decimal point. Only write the code once and use Handles.
6.
Code the
Enter event of each textbox so that the existing text will be
highlighted when the text box gets the focus.
7.
Code the TextC
hanged event of the textboxes. Erase the text in the two
answer labels
whenever the textbox contents changes
. Only write the code once
and use Handles.
Answer:
VB
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
        Dim decBalance As Decimal
        Dim decDeposits As Decimal
        Dim decWithdrawls As Decimal
        Dim blnConverted As Boolean
        Dim decearned As Decimal
        Dim decending As Decimal
        Dim decSubTotal As Decimal

        blnConverted = Integer.TryParse(TextBox1.Text, decBalance)
        If blnConverted = False Then
            MessageBox.Show("Error")
            TextBox1.Focus()
            Exit Sub
        End If

        blnConverted = Integer.TryParse(TextBox2.Text, decDeposits)
        If blnConverted = False Then
            MessageBox.Show("Error")
            TextBox2.Focus()
            Exit Sub
        End If

        blnConverted = Integer.TryParse(TextBox3.Text, decWithdrawls)
        If blnConverted = False Then
            MessageBox.Show("Error")
            TextBox3.Focus()
            Exit Sub
        End If

        decSubTotal = (decBalance + decDeposits + decWithdrawls)
        If decSubTotal > 500.0 Then
            decearned = 0.02
        End If

        decending = (decSubTotal + decearned)

        lblInterest.Text = decearned.ToString("C")
        lblEnding.Text = decending.ToString("C")
    End Sub

End Class
Posted
Comments
Thanks7872 8-Oct-13 2:09am    
Whats the question? What is the problem? Post the smallest possible code snippet you faced problem with and clearly explain what it does and what you expected to do it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900