SUNIL GUTTA

SUNIL GUTTA

  • NA
  • 1k
  • 395.6k

Minor modifications and help with loops req'd

Oct 23 2013 9:27 AM

Hello guys


I am very close to finishing this project, I just need some guidance for the second loop. I was told to use a do loop since that is all we have learned so far in class. If the user clicks 4, it needs to show that year and all previous years. No idea how to do that! So here is the question from Microsoft Visual Basic 2010 chapter 6 (I've shortened it so send me a message if you need the rest:


Create an application that the company's accountant can use to calculate an asset's annual depreciation.....The accountant will enter the asset's cost, useful life (in years), and a salvage value (which is the value of the asset at the end of its useful life). Use a list box to allow the user to select the useful life. Display numbers 3-20 in list box. The application should use the double-declining balance method to calculate the depreciation... using Financial.DDB method to calculate depreciation. The method's syntax is Financial.DDB(cost, salvage, life, period). In the syntax, the cost, salvage, and life arguments are the asset's cost, salvage, value, and useful life. The period argument is the period for which you want the depreciation amount calculated...Below the Depreciation schedule label is a text box whole Multiline and ReadOnly properties are set to True, and wholse ScrollBars propery is set to vertical.


Here is the code I have so far:


'Manufacturing Company Application

Option Explicit On
Option Strict On
Option Infer Off


Public Class Main_Form

Private Sub close_Click(sender As Object, e As EventArgs) Handles ex.Click
Me.Close()
End Sub

Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

'MainForm_Load allows code to be shown as soon as interface is open
'fills the list box with options to chose from years 3-20
Dim year As Integer = 3
Do While year <= 20
usefulLifeBox.Items.Add(year.ToString)
year = year + 1
Loop

End Sub

Private Sub displayButton_Click(sender As Object, e As EventArgs) Handles displayButton.Click

Dim cost, salvage, life As Double
Dim period As Double = 3
Dim depreciation As Double
Dim convertedCost, convertedLife, convertedSalvage, convertedPeriod As Boolean


convertedCost = Double.TryParse(assetCostBox.Text, cost)
convertedLife = Double.TryParse(usefulLifeBox.Text, life)
convertedSalvage = Double.TryParse(salvageValueBox.Text, salvage)
convertedPeriod = Double.TryParse(usefulLifeBox.Text, period)

Do While depreciation = Financial.DDB(cost, salvage, life, period)
period = period + 1
Loop


If convertedCost AndAlso convertedLife AndAlso convertedSalvage Then
scheduleBox.Text = "Year: " & ControlChars.Tab & " Depreciation: "

Else
MessageBox.Show("The cost, life, and salvage values must be numeric.", _
"Attention!", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End If

End Sub

Private Sub assetCostBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles assetCostBox.KeyPress

If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If

End Sub

Private Sub salvageValueBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles salvageValueBox.KeyPress

If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If

End Sub

Private Sub cost_Click(sender As Object, e As EventArgs) Handles cost.Click

End Sub

Private Sub assetCostBox_TextChanged(sender As Object, e As EventArgs) Handles assetCostBox.TextChanged

End Sub
End Class

Cheers ty mate

Answers (1)