Welcome Guest!
 VB 6 Helper
 Previous Message All Messages Next Message 
VB 6 Helper Newsletter  Rod Stephens
 Aug 22, 2011 09:29 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

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!


Twitter feeds:

    VB6 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 6
3. New HowTo: Calculate how long it will take to pay off a credit card
by making minimum payments in Visual Basic 6
1. New HowTo: Graph savings from a normal bank account, a 401(k), and a
Roth IRA account in Visual Basic .NET

(picture at http://www.vb-helper.com/howto_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

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 6

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 cmdGo_Click()
Dim monthly_contribution As Double
Dim num_months As Integer
Dim interest_rate As Double
Dim balance As Double
Dim i As Integer
Dim new_item As ListItem
Dim interest As Double

    ' Get the parameters.
    monthly_contribution = ParseCurrency(txtMonthlyContribution.Text)
    num_months = Val(txtNumMonths.Text)
    interest_rate = ParsePercent(txtInterestRate.Text) / 12

    ' Calculate.
    balance = 0
    For i = 1 To num_months
        ' Display the month.
        Set new_item = lvwBalance.ListItems.Add(Text:=Format$(i))

        ' Display the interest.
        interest = balance * interest_rate
        new_item.ListSubItems.Add Text:=FormatCurrency$(interest)

        ' Add the contribution.
        balance = balance + monthly_contribution

        ' Display the balance.
        balance = balance + interest
        new_item.ListSubItems.Add Text:=FormatCurrency$(balance)
    Next i

    ' Scroll to the last entry.
End Sub
3. New HowTo: Calculate how long it will take to pay off a credit card
by making minimum payments in Visual Basic 6

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

The following code does all the work.

' Calculate the payments.
Private Sub cmdGo_Click()
Dim balance As Double
Dim interest_rate As Double
Dim payment_percent As Double
Dim min_payment As Double
Dim total_payments As Double
Dim new_item As ListItem
Dim payment As Double
Dim interest As Double
Dim i As Integer
    ' Get the parameters.
    balance = ParseCurrency(txtInitialBalance.Text)
    interest_rate = ParsePercent(txtInterestRate.Text) / 12
    payment_percent = ParsePercent(txtPaymentPercent.Text)
    min_payment = ParseCurrency(txtMinPayment.Text)

    lblResult.Caption = ""
    total_payments = 0

    ' Display the initial balance.
    Set new_item = lvwPayments.ListItems.Add(Text:="0")
    new_item.ListSubItems.Add Text:=""
    new_item.ListSubItems.Add Text:=""
    new_item.ListSubItems.Add Text:=FormatCurrency$(balance)

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

        ' Calculate interest.
        interest = balance * interest_rate
        balance = balance + interest

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

        ' Display results.
        Set new_item = lvwPayments.ListItems.Add(Text:=Format$(i))
        new_item.ListSubItems.Add Text:=FormatCurrency$(payment)
        new_item.ListSubItems.Add Text:=FormatCurrency$(interest)
        new_item.ListSubItems.Add Text:=FormatCurrency$(balance)

        ' Process the next month.
        i = i + 1

    ' Display the total payments.
    lblResult.Caption = FormatCurrency$(total_payments)
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 6"

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

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.

Twitter feeds:

Post questions at:
 Previous Message All Messages Next Message 
  Check It Out!

  Topica Channels
 Best of Topica
 Art & Design
 Books, Movies & TV
 Food & Drink
 Health & Fitness
 News & Information
 Personal Finance
 Personal Technology
 Small Business
 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.