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
24Hour 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# 24Hour Trainer."

Have a great week and thanks for subscribing!
Rod
RodSte@vbhelper.com
Twitter feeds:
VBHelper
CSharpHelper
==========
==========
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
==========
++++++++++
<VB6>
++++++++++
==========
1. New HowTo: Graph savings from a normal bank account, a 401(k), and a
Roth IRA account in Visual Basic .NET
http://www.vbhelper.com/howto_graph_401k.html
http://www.vbhelper.com/HowTo/howto_graph_401k.zip
(picture at http://www.vbhelper.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 pretax
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 posttax 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 sawtooth
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 6
http://www.vbhelper.com/howto_monthly_investment.html
http://www.vbhelper.com/HowTo/howto_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 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.
lvwBalance.ListItems.Clear
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.
lvwBalance.ListItems(lvwBalance.ListItems.Count).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 6
http://www.vbhelper.com/howto_credit_card_calculator.html
http://www.vbhelper.com/HowTo/howto_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/creditcards/minimumpaymentcalculator.aspx).
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.
lvwPayments.ListItems.Clear
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
Loop
' Display the total payments.
lblResult.Caption = FormatCurrency$(total_payments)
lvwPayments.ListItems(lvwPayments.ListItems.Count).EnsureVisible
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"
(http://www.vbhelper.com/howto_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



