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 ApplicationOption Explicit OnOption Strict OnOption Infer OffPublic Class Main_FormPrivate Sub close_Click(sender As Object, e As EventArgs) Handles ex.ClickMe.Close()End SubPrivate 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-20Dim year As Integer = 3Do While year <= 20usefulLifeBox.Items.Add(year.ToString)year = year + 1LoopEnd SubPrivate Sub displayButton_Click(sender As Object, e As EventArgs) Handles displayButton.ClickDim cost, salvage, life As DoubleDim period As Double = 3Dim depreciation As DoubleDim convertedCost, convertedLife, convertedSalvage, convertedPeriod As BooleanconvertedCost = 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 + 1LoopIf convertedCost AndAlso convertedLife AndAlso convertedSalvage ThenscheduleBox.Text = "Year: " & ControlChars.Tab & " Depreciation: "ElseMessageBox.Show("The cost, life, and salvage values must be numeric.", _"Attention!", MessageBoxButtons.OK, _MessageBoxIcon.Information)End IfEnd SubPrivate Sub assetCostBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles assetCostBox.KeyPressIf (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlsoe.KeyChar <> ControlChars.Back Thene.Handled = TrueEnd IfEnd SubPrivate Sub salvageValueBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles salvageValueBox.KeyPressIf (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlsoe.KeyChar <> ControlChars.Back Thene.Handled = TrueEnd IfEnd SubPrivate Sub cost_Click(sender As Object, e As EventArgs) Handles cost.ClickEnd SubPrivate Sub assetCostBox_TextChanged(sender As Object, e As EventArgs) Handles assetCostBox.TextChangedEnd SubEnd Class