Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleRoughly compare the savings a normal bank account would give versus a 401(k) (a US tax thing) in Visual Basic 6
DescriptionThis example shows how to roughly compare the savings a normal bank account would give versus a 401(k) (a US tax thing) in Visual Basic 6.
Keywordsbank account, savings, interest, tax, tax deferred, 401(k), VB.NET
CategoriesAlgorithms
 
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...

A 401(k) retirement plan lets you save money tax deferred. As I understand it, that means you don't pay tax on that money before you put it into the plan and any interest the money accrues is not taxed. When you remove money from the plan, you pay taxes on it. There are also penalties if you withdraw money before retirement age (which will probably be around 140 by the time I retire).

Enter the annual contribution you would make to the plan, your income tax rate, the annual interest rate you expect to earn, and the number of years you want to examine. When you click Go, the following code executes.

The code gets your inputs. It then loops through the years calculating balances for a normal bank account and for a 401(k).

For the bank account, the code calculates your interest for the previous year, adds that to your contribution, subtracts taxes from both, and adds the result to the account balance.

For the 401(k), the calculation is the same except the program does not subtract taxes.

 
Private Sub cmdGo_Click()
Dim annual_contribution As Single
Dim tax_rate As Single
Dim interest_rate As Single
Dim num_years As Integer
Dim balance_bank As Single
Dim balance_401k As Single
Dim i As Integer

    annual_contribution = _
        Val(Replace(Replace(txtAnnualContribution.Text, _
            "$", ""), ",", ""))

    tax_rate = Val(Replace(txtTaxRate.Text, "%", "")) / 100
    ' See how big it is.
    If tax_rate >= 1 Then
        ' It's a percentage as in 5%.
        tax_rate = tax_rate / 100
    End If

    interest_rate = Val(Replace(txtInterestRate.Text, "%", _
        "")) / 100
    ' See how big it is.
    If interest_rate >= 1 Then
        ' It's a percentage as in 5%.
        interest_rate = interest_rate / 100
    End If

    num_years = Val(txtYears.Text)

    balance_bank = 0
    balance_401k = 0
    lstResults.Clear
    lstResults.AddItem "Year" & vbTab & "Bank" & vbTab & _
        "401(k)"
    For i = 0 To num_years
        lstResults.AddItem i & vbTab & _
            FormatCurrency(balance_bank) & vbTab & _
            FormatCurrency(balance_401k)

        ' Bank balance += interest + contribution, minus
        ' taxes.
        balance_bank = balance_bank + _
            (1 - tax_rate) * (balance_bank * interest_rate _
                + annual_contribution)

        ' 401(k) balance += interest + contribution.
        balance_401k = balance_401k + _
            (balance_401k * interest_rate + _
                annual_contribution)
    Next i
End Sub
 
Over many years, the difference between a bank account and a 401(k) can be quite large. Also many larger employers match 491(k) contributions at least to an extent, further increasing the difference.

(If you know more about these types of accounts and want to chime in, let me know.)

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated