# Creating a simple depreciation calculator

• 13 years ago

Greetings currently I'm having issues in developing a simple depreciation calculator. Basically I have two inputs Intial Cost and Salvage that can be entered via a textbox. My 3rd input is Years in which I called Life in my code basically I created a combobox in which users can select 1-20 years. Also I've created two radio buttons which enable a user to choose one of the two depreciation methods. I used SLN and SYD which are Straight Line and Sum of Years depreciation method. When all the inputs are entered and I press the calculate button I want the information to be displayed via ListView. However this is where my problem is. I'm not able to populate the ListView when I entered all my inputs. I think my event procedure (Calc) isn't correctly calling the general sub procedure. If anyone could provide some insight or general input on how to help make this calculator function. I'd be very greatful. Thank you for your time and I hope everyone is having a good week so far.

Public

Class Form1

Private Function SLN(ByVal Cost As Double, ByVal Salvage As Double, _

ByVal Life As Double) As Double

Dim CalcDepre As Decimal

Private Function SYD(ByVal Cost As Double, ByVal Salvage As Double, _

ByVal Life As Double, ByVal Period As Double) As Double

Dim CalcDepre As Decimal

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

Dim Cost As Decimal

Dim Salvage As Decimal

Dim Years As Integer

Dim Eqt As String

Dim row As ListViewItem

lvwDeprec.Items.Clear()

For Life = 1 To 20

Next

Cost = Val(txtCost.Text)

Salvage = Val(txtSal.Text)

Life = Val(cboLife.Text)

Eqt =

"SLN"

End If

Eqt =

"SYD"

End If

Update = CalcDepre(Cost, Salvage, Eqt, Life)

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

Me.Close()

End Sub

End

Class
• 13 years ago

Public Class Form1&nbsp; </P> <P>Private Function SLN(ByVal Cost As Double, ByVal Salvage As Double, _
&nbsp;&nbsp;&nbsp; ByVal Life As Double) As Double
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim CalcDepre As Decimal</P> <P>&nbsp;&nbsp;&nbsp; Private Function SYD(ByVal Cost As Double, ByVal Salvage As Double, _
&nbsp;&nbsp;&nbsp; ByVal Life As Double, ByVal Period As Double) As Double
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim CalcDepre As Decimal</P> <P>&nbsp;&nbsp;&nbsp; Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Cost As Decimal
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Salvage As Decimal
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Years As Integer
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Eqt As String
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim row As ListViewItem</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lvwDeprec.Items.Clear()</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Life = 1 To 20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cost = Val(txtCost.Text)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Salvage = Val(txtSal.Text)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Life = Val(cboLife.Text)</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If radStraight.Checked Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Eqt = "SLN"</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If radSum.Checked Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Eqt = "SYD"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</P> <P>&nbsp;</P> <P>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Update = CalcDepre(Cost, Salvage, Eqt, Life)
&nbsp;&nbsp;&nbsp; End Sub</P> <P>&nbsp;&nbsp;&nbsp; Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Me.Close()
&nbsp;&nbsp;&nbsp; End Sub
End Class

Greetings My Code is incomplete as I'm unsure on how to proceed in effectively creating a simple depreciation calculator and ensure the results are displayed in the List view.

Currently the Form I've created contains:

Intial Cost: TextBox
Salvage Value: TextBox
Life: ComboBox

Display Result: ListView

Caculate: Button
Exit: Button

The user will enter in Intial Cost, Salvage Value, and select Life from dropdown list 1-20. After which they can select the depreciation calculation method via the radio button. Once caculate button is pressed the results show up in the List View. I hope you or anyone else will be able to help me through this complex issue. Thank you for your time

• 13 years ago

Public Class Form1&nbsp; </P> <P>Private Function SLN(ByVal Cost As Double, ByVal Salvage As Double, _
&nbsp;&nbsp;&nbsp; ByVal Life As Double) As Double
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim CalcDepre As Decimal</P> <P>&nbsp;&nbsp;&nbsp; Private Function SYD(ByVal Cost As Double, ByVal Salvage As Double, _
&nbsp;&nbsp;&nbsp; ByVal Life As Double, ByVal Period As Double) As Double
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim CalcDepre As Decimal</P> <P>&nbsp;&nbsp;&nbsp; Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Cost As Decimal
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Salvage As Decimal
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Years As Integer
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Eqt As String
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim row As ListViewItem</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lvwDeprec.Items.Clear()</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Life = 1 To 20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cost = Val(txtCost.Text)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Salvage = Val(txtSal.Text)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Life = Val(cboLife.Text)</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If radStraight.Checked Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Eqt = "SLN"</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If radSum.Checked Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Eqt = "SYD"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</P> <P>&nbsp;</P> <P>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Update = CalcDepre(Cost, Salvage, Eqt, Life)
&nbsp;&nbsp;&nbsp; End Sub</P> <P>&nbsp;&nbsp;&nbsp; Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Me.Close()
&nbsp;&nbsp;&nbsp; End Sub
End Class

Greetings XTab. My Code is incomplete as I'm unsure on how to proceed in effectively creating a simple depreciation calculator and ensure the results are displayed in the List view.

Currently the Form I've created contains:

Intial Cost: TextBox
Salvage Value: TextBox
Life: ComboBox

Display Result: ListView

Caculate: Button
Exit: Button

The user will enter in Intial Cost, Salvage Value, and select Life from dropdown list 1-20. After which they can select the depreciation calculation method via the radio button. Once caculate button is pressed the results show up in the List View. I hope you or anyone else will be able to help me through this complex issue. Thank you for your time

• 13 years ago

Your code in the first post is difficult to follow.  The code in your second and third posts is impossible to follow because it's just jumbled text.  From what I can see in your first post you have two Functions...SLN and SYD.  However, neither function has any code and neither one ever gets called.  You've declared CalcDepre as a double in both those functions.  However, in the button click event CalcDepre appears to be a function (which I can't find in your code anywhere). Here are a couple of tips.

1) Comment your code.  This is good practice and will help someone like me figure out what's going on
2) When your posting code click on the HTML tab just above the post button.  Then use the <pre></pre> tags to post your code.  Everything in between these two tags will retain there formatting and will appear in a yellow box. This makes reading your code a whole lot easier.

`This is where your code would appear.`
As I said from what I can tell I don't have enough of your code to figure out what's going on. It appears the code for the most important procedures are missing. Try posting all your code again taking into account my suggestions and hopefully we'll get to the bottom of this.

### Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

### Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It works on my machine.”