Solved: VB 2008 Help

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Coke23

Thread Starter
Joined
Mar 24, 2010
Messages
12
Im new at this i know im doing something wrong. This is my project
$15000 is deposited into a savings paying 5 % interest and $1000 is withdrawn at
the end of each year. How many years will it take for the account to be depleted.

Note if at the end of a certain year the balance is $1000 or less, then the final
withdrawl will consist of that balance and the account will be depleted.

this is the code i have but something is not write can anyone help PLS :eek:
Private Sub btnYears_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYears.Click
Dim Deposite = 15000
Dim Interest = 0.05
Dim Subtract = 1000
Dim Years = 1
Do While Deposite <= 15000
Deposite = (Deposite * Interest) + Subtract
Years += 1
Loop
txtYears.Text = " The number of years to deplete 15000 = " & Years
End Sub
 
Joined
Apr 3, 2010
Messages
5
You are adding "$1000" to the "account" every iteration (line 8). Try this, and then write again if there is still a problem.

Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] btnYears_Click([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]  System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] btnYears.Click
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Deposite = 15000
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Interest = 0.05
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Subtract = 1000
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Years = 1
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Do[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] While[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Deposite <= 15000
Deposite = (Deposite * Interest)[/SIZE] - [SIZE=2]Subtract
Years += 1
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Loop
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]txtYears.Text = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]" The number of years to deplete 15000 =  "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] & Years
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] Sub[/COLOR][/SIZE][/COLOR][/SIZE]
 

Coke23

Thread Starter
Joined
Mar 24, 2010
Messages
12
Thanks Thread told u i was new at this and it would be something simple.
i was using the + Subtract as ( and subtract).
I changed what u said and i still got a warning (Arithmetic operation resulted in an overflow.)
so i changed the
Do While Deposite <= 15000 to
Do
While Deposite = 15000

I get an answer of 2 years. hopefully this is it.
Thanks again Thread


 
Joined
Jul 28, 2008
Messages
1,899
Two years seems a bit short for $15,000. You also need to work out the interest, add it to the account balance then take the withdrawal. At the moment you are setting the account balance to the interest minus the withdrawal, which will give you an incorrect answer.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top