Welcome Guest!
 VB.NET Helper
 Previous Message All Messages Next Message 
VB .NET Helper Newsletter  Rod Stephens
 Aug 22, 2011 09:30 PDT 

What with the markets going bonkers in the past week, this newsletter's
examples have a decidedly financial theme.
-----
I think I've figured out one of the reasons my book "Visual Basic
24-Hour Trainer" isn't doing well: most of the people on this mailing
list already know .NET. If you're one of those people, I would not
recommend the book for you. It's definitely a beginner's book.

However, if you know someone who is interested in learning to program
(or who needs to for work), please recommend that they at least consider
the book. (If sales for the VB book don't pick up fast, there will be no
second edition. It would be a shame because I think it's a pretty good
book.)

And you may want to take a look at the screencasts I've posted so you
can get an idea of what that feature is like. I think they can be
helpful for lots of beginners.

You may already know .NET, but you may find a similar approach useful in
my book "C# 24-Hour Trainer."
-----
Have a great week and thanks for subscribing!

Rod
RodSte-@vb-helper.com

Twitter feeds:
    VBHelper
    CSharpHelper
==========
==========

    VB.NET Contents:
1. New HowTo: Graph savings from a normal bank account, a 401(k), and a
Roth IRA account in Visual Basic .NET
2. New HowTo: Calculate the future value of a monthly investment with
interest in Visual Basic .NET
3. New HowTo: Calculate how long it will take to pay off a credit card
by making minimum payments in Visual Basic .NET
==========
++++++++++
      <VB.NET>
++++++++++
==========
1. New HowTo: Graph savings from a normal bank account, a 401(k), and a
Roth IRA account in Visual Basic .NET
http://www.vb-helper.com/howto_net_graph_401k.html
http://www.vb-helper.com/HowTo/howto_net_graph_401k.zip

(Picture at http://www.vb-helper.com/howto_net_graph_401k.png.)

Important Note: I am not a tax or investment professional. I don't even
pretend to understand this stuff. This is a very simple tool for playing
with numbers (it doesn't even compound continuously) and I don't vouch
for its correctness. It should in no way be taken for investment advice.
What, are you crazy???

That said...

This example graphs the savings you would get by making annual
contributions to a savings account, a 401(k), and a Roth IRA. As far as
I can tell, these are the rules:

    - In a traditional bank account, interest is taxed each year. Money
you plan to put into the account is taxed first. This program takes
taxes out of the annual contribution.
    - In a 401(k) account, the annual contribution is taken from pre-tax
money so it is not taxed. Interest is also not taxed. When you withdraw
the money, it is all taxed at your current rate. (One advantage to this
type of account is that you may be paying at a lower rate when you
retire than you would pay when you make contributions.) There may also
be a penalty for early withdrawal.
    - In a Roth IRA, annual contributions are post-tax so this example
withholds taxes from the contributions. withdrawals are not taxed,
although there may be a penalty for early withdrawal.
    - These are not the only rules. For example, you may be allowed to
make early withdrawals without penalty in case of hardship. The program
doesn't do anything about these extra rules.

This program marches through each of the years specified, calculating
new balances each year, and displays the results. Notice the saw-tooth
result for the savings account as taxes are removed each year.

Interestingly the 401(k) and Roth IRA produce the same final result if
the tax rate you pay on the withdrawal is the same as the rate you paid
while making contributions. If the rate is lower, the 401(k) does
better.

If you understand this stuff better than I do and want to make
corrections, please let me know and I'll update the program.
==========
2. New HowTo: Calculate the future value of a monthly investment with
interest in Visual Basic .NET
http://www.vb-helper.com/howto_net_monthly_investment.html
http://www.vb-helper.com/HowTo/howto_net_monthly_investment.zip

The magic of compound interest is that, over time, you get interest on
the interest

For each month the program calculates the interest on the account
balance. It then adds the interest and a monthly contribution to the
balance and displays the result. (Note that interest is compounded
monthly not continuously.)

The following code shows how the program performs its calculations.

' Calculate the interest compounded monthly.
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGo.Click
    ' Get the parameters.
    Dim monthly_contribution As Decimal = Decimal.Parse( _
        txtMonthlyContribution.Text, NumberStyles.Any)
    Dim num_months As Integer = Integer.Parse(txtNumMonths.Text)
    Dim interest_rate As Decimal = Decimal.Parse( _
        txtInterestRate.Text.Replace("%", "")) / 100
    interest_rate /= 12

    ' Calculate.
    lvwBalance.Items.Clear()
    Dim balance As Decimal = 0
    For i As Integer = 1 To num_months
        ' Display the month.
        Dim new_item As ListViewItem =
lvwBalance.Items.Add(i.ToString())

        ' Display the interest.
        Dim interest As Decimal = balance * interest_rate
        new_item.SubItems.Add(interest.ToString("c"))

        ' Add the contribution.
        balance += monthly_contribution

        ' Display the balance.
        balance += interest
        new_item.SubItems.Add(balance.ToString("c"))
    Next i

    ' Scroll to the last entry.
    lvwBalance.Items(lvwBalance.Items.Count - 1).EnsureVisible()
End Sub
==========
3. New HowTo: Calculate how long it will take to pay off a credit card
by making minimum payments in Visual Basic .NET
http://www.vb-helper.com/howto_net_credit_card_calculator.html
http://www.vb-helper.com/HowTo/howto_net_credit_card_calculator.zip

For each month the program:

    - Calculates the payment first. This is either a percent of the
balance or the minimum amount, whichever is greater.
    - Calculates interest after the payment is calculated but before it
is subtracted from the balance.
    - Adds the interest to the balance.
    - If the payment is greater than the balance, the payment is set
equal to the balance.
    - Subtracts the payment from the balance.
    - Displays the results for the month.

This method agrees well with the calculator at Bizrate.com
(http://www.bankrate.com/calculators/credit-cards/minimum-payment-calculator.aspx).


The following code does all the work.

' Calculate the payments.
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGo.Click
    ' Get the parameters.
    Dim balance As Decimal = Decimal.Parse(txtInitialBalance.Text,
NumberStyles.Any)
    Dim interest_rate As Decimal =
Decimal.Parse(txtInterestRate.Text.Replace("%", "")) / 100
    Dim payment_percent As Decimal =
Decimal.Parse(txtPaymentPercent.Text.Replace("%", "")) / 100
    Dim min_payment As Decimal = Decimal.Parse(txtMinPayment.Text,
NumberStyles.Any)
    interest_rate /= 12

    txtTotalPayments.Clear()
    Dim total_payments As Decimal = 0

    ' Display the initial balance.
    lvwPayments.Items.Clear()
    Dim new_item As ListViewItem = lvwPayments.Items.Add("0")
    new_item.SubItems.Add("")
    new_item.SubItems.Add("")
    new_item.SubItems.Add(balance.ToString("c"))

    ' Loop until balance == 0.
    Dim i As Integer = 1
    Do While (balance > 0)
        ' Calculate the payment.
        Dim payment As Decimal = balance * payment_percent
        If (payment < min_payment) Then payment = min_payment

        ' Calculate interest.
        Dim interest As Decimal = balance * interest_rate
        balance += interest

        ' See if we can pay off the balance.
        If (payment > balance) Then payment = balance
        total_payments += payment
        balance -= payment

        ' Display results.
        new_item = lvwPayments.Items.Add(i.ToString())
        new_item.SubItems.Add(payment.ToString("c"))
        new_item.SubItems.Add(interest.ToString("c"))
        new_item.SubItems.Add(balance.ToString("c"))

        ' Process the next month.
        i += 1
    Loop

    ' Display the total payments.
    txtTotalPayments.Text = total_payments.ToString("c")
End Sub

To model a fixed payment (for example, $200 per month), set Payment % to
0 and set Min Payment to the monthly amount you want to pay.

Note that if you don't rack up this big debt and you put the payments in
a savings account or some other investment, then compound interest will
work in your favor instead of against you and you'll make money instead
of paying out a lot of interest. For an example that calculates compound
interest with a monthly investment, see "Calculate the future value of a
monthly investment with interest in Visual Basic .NET"
(http://www.vb-helper.com/howto_net_monthly_investment.html).

Suppose you want to buy something for $5,000.00. Using this example and
the default settings, you end up paying $8,109.24 over 138 months.
That's an average payment of $58.76, although in fact you pay a lot more
in the beginning because your minimum payment is larger when the balance
is bigger.

Instead of putting the $5,000.00 on your credit card, suppose you put
$60.00 per month in an account that pays 7.00% interest. After only 69
months you would have saved $5,079.20. You would have enough for the
$5,000.00 purchase with a little left over in half the time it would
have taken you to pay off the credit card debt and with smaller payments
initially!

Of course, there are a couple of catches. First, can you find an
investment that pays 7.00% these days? If you only get a 1.00% return
(which is believable even now), you still raise $5,025.61 in 81 months.
That's not as fast but it's still a lot faster than paying off the
credit card debt and with smaller contributions.

The moral is that you can save a lot of money if you save up for
something instead of buying it on credit. You'll save the interest
payments and be finished saving sooner than you would be finished paying
off credit card debt.
==========
Archives:
    http://www.topica.com/lists/VBHelper
    http://www.topica.com/lists/VB6Helper
    http://www.topica.com/lists/VBNetHelper

Twitter feeds:
    VBHelper
    CSharpHelper

Post questions at:
    http://www.topica.com/lists/VBHelperQA
	
 Previous Message All Messages Next Message 
  Check It Out!

  Topica Channels
 Best of Topica
 Art & Design
 Books, Movies & TV
 Developers
 Food & Drink
 Health & Fitness
 Internet
 Music
 News & Information
 Personal Finance
 Personal Technology
 Small Business
 Software
 Sports
 Travel & Leisure
 Women & Family

  Start Your Own List!
Email lists are great for debating issues or publishing your views.
Start a List Today!

© 2001 Topica Inc. TFMB
Concerned about privacy? Topica is TrustE certified.
See our Privacy Policy.