Noob Math Solving Problem..

deathspawner

New member
Joined
Feb 12, 2005
Messages
1
Programming Experience
Beginner
Have this problem to solve in an exam, but no matter how much I try, I cannot figure it out. Here is a code snippet

VB.NET:
	 If radStraight.Checked Then
			Dim frmStr As String = "{0, -10} {1,12} {2,14} {3,12}"
			Dim x As Integer = 0
			Deprec = (1 / Life) * Cost
			For i = 0 To Life - 1
			 Line = ((Year + i) & (Cost - TotalDeprec) & Deprec & (TotalDeprec + Deprec))
			 lstSchedule.Items.Add(String.Format(frmStr, "test", "test", "test", "test"))
			 lstSchedule.Items.Add(String.Format(frmStr, Year + i, Year + i, Year + i, Year + i))
			 lstSchedule.Items.Add(String.Format(frmStr, (x), (Cost - TotalDeprec), (Cost - TotalDeprec), (Cost - TotalDeprec)))
			 lstSchedule.Items.Add(String.Format(frmStr, Deprec, Deprec, Deprec, Deprec))
			 lstSchedule.Items.Add(String.Format(frmStr, TotalDeprec = TotalDeprec + Deprec, TotalDeprec = TotalDeprec + Deprec, TotalDeprec = TotalDeprec + Deprec, TotalDeprec = TotalDeprec + Deprec))
			Next i

I am sure you could tell what's going on through the code.. but the problem is.. it will spit out the values all the same. It won't work the way it's supposed to.

It's supposed to depreciate the value of owing over time, but it's not carrying over the values as I'd like. Also, for some values, it spits out a False.. and I can't figure that out.

Sorry if I left out some details, please let me know what I forgot to mention.

Thanks for any help!
 
VB has great built in debugger tools. Set a breakpoint in your code using F9, then run the program and proceed step by step with F11. Move the mouse over variables to see their values and go from there. Good luck!
 
Last edited:
Leaving out the string formatting, this is what I see should be happening:

dim depCost as decimal = cost
dim Deprec as Decimal = (1 / Life) * cost
For year = startYear to endYear
depCost = depCost - Deprec
'Do all the line printing here. Use year as the year#, depCost as the new 'Depreciated value.
Next 'Year

Now, you will probably have to adjust this based on when you are doing the depreciating, beginning of the year or end. In other words, is the first year value the original cost or after the first depreciation cycle.
 
Hi,

While Mneb's post will do the work required, the original post shows fundamental misunderstandings.

Assuming that somewhere else you have something like;

Dim Life As Integer
Dim Line As String
And that you ARE using VB.NET 2003 or 2002,

In

Line = ((Year + i) & (Cost - TotalDeprec) & Deprec & (TotalDeprec + Deprec))

you are mixing up strings and numerics.

Furthermore, what on earth is

lstSchedule.Items.Add(String.Format(frmStr, TotalDeprec = TotalDeprec + Deprec, TotalDeprec = TotalDeprec + Deprec, TotalDeprec = TotalDeprec + Deprec, TotalDeprec = TotalDeprec + Deprec))
Next i

supposed to produce?

What is the actual exam question?
 
Back
Top