1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: VB 2008 Help

Discussion in 'Software Development' started by Coke23, Apr 2, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. Coke23

    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
     
  2. gigglebyte

    gigglebyte

    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]
     
  3. Coke23

    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


     
  4. -Fabez-

    -Fabez-

    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.
     
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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/914385

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice