vb depreciation schedule

Page 1 of 1

13 Replies - 525 Views - Last Post: 23 April 2019 - 09:33 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=415771&amp;s=13228f1a29b0edc1b3796f7792089cc5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 kart1023

Reputation: 0
• Posts: 12
• Joined: 02-April 19

vb depreciation schedule

Posted 16 April 2019 - 08:20 AM

I am trying to create a depreciation schedule in VB using this formula A = P * (1-R/100)^n
where a is the value of the car after n years, P is the purchase amount, R is the percentage rate of depreciation. I was going to try to start this using cases, but my mentor said I should make it one big If statement. So I would like the user to be able to put in what they bought their car for, current vehicle age, and years owned the vehicle. He also said I could make it a large ladder if statement. My code is pretty weak so far I could just use some help getting started on this big if statement. If possible I'm trying to get the output to be a list of each year the user added showing the lost value then total worth at the end. also the rate I wanted to use for depreciation was 14%. Ill include a screen shot of the form and the way the results would show up.

```Public Class Depreciation

End Sub

Private Sub btnCalcDep_Click(sender As Object, e As EventArgs) Handles btnCalcDep.Click
Dim price As Decimal
Dim depreciation As Decimal
Dim Years As Integer
price = CDec(txtBoxPrice.Text)
depreciation = CDec(txtbxAge.Text)
Years = CInt(txtbxYears.Text)

If price = CDec price * (1) Then

End If
End Sub
```

Attached image(s)

This post has been edited by modi123_1: 16 April 2019 - 08:23 AM
Reason for edit:: In the future, please use the [code] tag button in the editor.

Is This A Good Question/Topic? 0

Replies To: vb depreciation schedule

#2 modi123_1

• Suitor #2

Reputation: 14995
• Posts: 59,870
• Joined: 12-June 08

Re: vb depreciation schedule

Posted 16 April 2019 - 08:37 AM

Why would you need an IF?

What have you tried when utilizing an IF statement?

#3 dbasnett

Reputation: 122
• Posts: 679
• Joined: 01-October 08

Re: vb depreciation schedule

Posted 16 April 2019 - 10:04 AM

There are some methods in https://docsmicrosof...basic.financial that might help.

#4 kart1023

Reputation: 0
• Posts: 12
• Joined: 02-April 19

Re: vb depreciation schedule

Posted 16 April 2019 - 10:46 AM

modi123_1, on 16 April 2019 - 08:37 AM, said:

Why would you need an IF?

What have you tried when utilizing an IF statement?

That's just what we have learned and been using in this class. I haven't really tried many things because I'm having trouble starting it.

#5 modi123_1

• Suitor #2

Reputation: 14995
• Posts: 59,870
• Joined: 12-June 08

Re: vb depreciation schedule

Posted 16 April 2019 - 11:18 AM

A good plan of attack is trying to fill out the variables.

So you got some user input, that's good. "after n years" can be found by looking at 'datetime.now' minus the entered date in years.
https://docs.microso...framework-4.7.2

All you need is "R is the percentage rate of depreciation." Where are you getting that?

#6 kart1023

Reputation: 0
• Posts: 12
• Joined: 02-April 19

Re: vb depreciation schedule

Posted 16 April 2019 - 11:44 AM

There was a site where I found a schedule and I'm trying to build it off that. They used that 14% R for average depreciation. I figured I would stick with that since it would be tougher to do a low, or higher depreciation rate as well

#7 modi123_1

• Suitor #2

Reputation: 14995
• Posts: 59,870
• Joined: 12-June 08

Re: vb depreciation schedule

Posted 16 April 2019 - 11:53 AM

Okay.. so then.. it seems like you have the components to jam in that formula and output.

#8 kart1023

Reputation: 0
• Posts: 12
• Joined: 02-April 19

Re: vb depreciation schedule

Posted 16 April 2019 - 12:13 PM

Yes. I think I'm just having trouble understanding how I should go about that

#9 modi123_1

• Suitor #2

Reputation: 14995
• Posts: 59,870
• Joined: 12-June 08

Re: vb depreciation schedule

Posted 16 April 2019 - 12:33 PM

Have some variable be assigned the result of "P * (1-R/100)^n".. after you substitute your variables for those formula variables.

#10 kart1023

Reputation: 0
• Posts: 12
• Joined: 02-April 19

Re: vb depreciation schedule

Posted 22 April 2019 - 04:36 PM

```Public Class Depreciation
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim vehiclepurchaseprice As Integer
Dim currentvehicleage As Double
Dim depreciationpercentage As Integer
Dim totaldepreciation As Integer
Dim valueofvehicle As Integer
Dim depreciationrate As Double = 0.15 \
Dim todaydate as Date = date.Now()
Dim N As Integer

vehiclepurchaseprice = CInt(TxtBoxPurchasePrice.Text)
currentvehicleage = CDbl(txtboxAge.Text)
depreciationpercentage = CInt(txtboxTotalPercentage.Text)
totaldepreciation = CInt(txtboxTotalDep.Text)
valueofvehicle = CInt(txtbxValueend.Text)

If vehiclepurchaseprice < 0 Then RadioButton2 = checked Then
N = todaydate - currentvehicleage
currentvehicleage = vehiclepurchaseprice * (1 - depreciationrate / 100)
totaldepreciation = vehiclepurchaseprice - currentvehicleage
ElseIf

currentvehicleage = vehiclepurchaseprice * (1 - depreciationrate / 100)
totaldepreciation = vehiclepurchaseprice - currentvehicleage
End If

```

here's what I have so far

#11 andrewsw

• quantum multiprover

Reputation: 6792
• Posts: 28,050
• Joined: 12-December 12

Re: vb depreciation schedule

Posted 23 April 2019 - 12:01 AM

That code has a number of basic syntax errors that need to be corrected.

#12 kart1023

Reputation: 0
• Posts: 12
• Joined: 02-April 19

Re: vb depreciation schedule

Posted 23 April 2019 - 05:36 PM

```lic Class FormDepreciation
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'variable purchase year, purchase price, and depreciation
'this depreciation schedule will have to be updated as each year passes
'since its 2019 you cant find the depreciation of a brand new vehicle

Dim Year As Decimal = 2019 - CDec(txtYear.Text)
Dim purchaseprice As Decimal = CDec(txtPrice.Text)
Dim depreciation As Decimal
'here is a procedure similar to the tax problem we worked in class
' in the first year of the vehicles life it will depreciate by 25%
' after the first year the vehicle will continually depreciate byt 15.6%
Select Case Year
Case Is = 1
depreciation = CDec(purchaseprice * 0.25)
Case Else
depreciation = CDec(purchaseprice * ((1 - 0.156) ^ Year))
End Select

txttotaldep.Text = depreciation.ToString

txtcarvalue.Text = CStr(purchaseprice - depreciation)
```

I started over. right now this only seems to work right when the vehicle is twenty years old. from the site where I am trying to build a similar schedule

#13 kart1023

Reputation: 0
• Posts: 12
• Joined: 02-April 19

Re: vb depreciation schedule

Posted 23 April 2019 - 09:15 PM

```**Mod: removing name.. derrr.**

8:58 PM (1 hour ago)
to me

Public Class FormDepreciation
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'variable purchase year, purchase price, and depreciation
'this depreciation schedule will have to be updated as each year passes
'since its 2019 you cant find the depreciation of a brand new vehicle

Dim Year As Decimal = 2019 - CDec(txtYear.Text)
Dim purchaseprice As Decimal = CDec(txtPrice.Text)
Dim depreciation, dep As Decimal
Dim rate As Double
'here is a procedure similar to the tax problem we worked in class
' in the first year of the vehicles life it will depreciate by 25%
' after the first year the vehicle will continually depreciate byt 15.6%
rate = 0.156
depreciation = CDec(purchaseprice * 0.25)
purchaseprice -= depreciation
'For i As Decimal = 2 To Year
'    If rate < 0.04 Then
'        If i <= 4 Then
'            dep += CDec(purchaseprice * ((1 - rate) ^ i))
'            purchaseprice -= dep
'            rate -= 0.03
'        ElseIf i > 4 And i <= 8 Then
'            dep += CDec(purchaseprice * ((1 - rate) ^ i))
'            purchaseprice -= dep
'            rate -= 0.04
'        ElseIf i > 8 And i < 10 Then
'            dep += CDec(purchaseprice * ((1 - rate) ^ i))
'            purchaseprice -= dep
'            rate -= 0.05
'        End If
'    Else
'        rate = 0.04
'        If i < 4 Then
'            dep += CDec(purchaseprice * ((1 - rate) ^ i))
'            purchaseprice -= dep
'            rate -= 0.03
'        ElseIf i > 4 And i <= 8 Then
'            dep += CDec(purchaseprice * ((1 - rate) ^ i)))
'            purchaseprice -= dep
'            rate -= 0.04
'        ElseIf i > 8 And i < 10 Then
'            dep += CDec(purchaseprice * ((1 - rate) ^ i)))
'            purchaseprice -= dep
'            rate -= 0.05
'        End If
'    End If

'Next
depreciation += dep
'Select Case Year
'    Case Is = 1

'    Case Else
'        depreciation = CDec(purchaseprice * ((1 - 0.156) ^ Year))
'End Select

txttotaldep.Text = depreciation.ToString

txtcarvalue.Text = CStr(purchaseprice - depreciation)
'error messages if input boxes are left blank
If txtPrice.Text = "" Then
txtPrice.Focus()
End If
If txtYear.Text = "" Then
End If
'error messages if value entered is not numberic
If txtPrice.Text = Text() Then
End If
If txtYear.Text = Text() Then
End If

End Sub
End Class
```

latest attempt the math still isnt right for this equation
the only two outputs I am trying to get are the : total depreciation of the vehicle and the value of vehicle at the end
My two inputs are vehicle Year and Vehicle purchase price.
I just cant figure out the right equation

This post has been edited by modi123_1: 23 April 2019 - 09:27 PM
Reason for edit:: Name removed.

#14 modi123_1

• Suitor #2

Reputation: 14995
• Posts: 59,870
• Joined: 12-June 08

Re: vb depreciation schedule

Posted 23 April 2019 - 09:33 PM

I don't get it. Your formula/equation is in your first post. Like I said earlier - get your inputs into variables, fit it into the equation (use parenthesis to make sure the order of operations are respected) and there you go.