What's New
Q & A
Tip Jar
C# Helper...
Follow VBHelper on Twitter Follow VBHelper on Twitter
MSDN Visual Basic Community
TitleCalculate how long it will take to pay off a credit card by making minimum payments in Visual Basic 6
DescriptionThis example shows how to calculate how long it will take to pay off a credit card by making minimum payments in Visual Basic 6.
Keywordsmathematics, algorithms, finance, credit card, pay off credit card, minimum payments, example, example program, Windows Forms programming, Visual Basic 6, VB 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 = _

        ' 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 = _
        new_item.ListSubItems.Add _
        new_item.ListSubItems.Add _
        new_item.ListSubItems.Add _

        ' 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 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.

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