wilsonwerks
05-02-2001, 06:25 PM
I have three problems with the following loop program:
1) How do I do I print string info before each loop value? (eg.: "After two years"; value, "After three years"; value, etc.)
2) I'm losing the original value of "cost" because the first loop redifines it as zero. I tried putting "ByVal cost" in the click event and DoubleDeclining sub procedure but it didn't work.
3) DoubleDeclining needs to depreciate 2/nths of the new value every year, not depreciate the same amount every year.
Until the last year when it wipes out the remaing balance.
The user defines the number of years to be depreciated.
Option Explicit
Private Sub cmdCalculate_Click()
Dim item As String, year As String
Dim cost As Single, number As Integer
Dim depreciation As Single, n As Integer
Call InputData(item, year, cost, number)
Call StraightLine(item, year, cost, number, depreciation)
Call DoubleDeclining(item, year, cost, number, depreciation)
End Sub
Private Sub InputData(item As String, year As String, cost As Single, number As Integer)
item = txtItem.Text
year = txtYear.Text
number = Val(txtNumber.Text)
cost = Val(txtCost.Text)
End Sub
Private Sub StraightLine(item As String, year As String, cost As Single, number As Integer, depreciation As Single)
'Calculate Straight Line Depreciation
depreciation = cost * (1 * (1 / number))
picDisplay.Print "The Straight Line Depreciation Schedule for your"
picDisplay.Print item; ", purchased in the year "; year; " at the"
picDisplay.Print "cost of"; cost; "is as follows:"
picDisplay.Print "The value after one year is:";
Do While cost > 0
cost = cost - depreciation
picDisplay.Print cost
Loop
End Sub
Private Sub DoubleDeclining(item As String, year As String, cost As Single, number As Integer, depreciation As Single)
'Calculate Straight Line Depreciation
depreciation = cost * (1 * (2 / number))
picDisplay.Print "The Double Declining Balance Depreciation Schedule"
picDisplay.Print "for your "; item; ", purchased in the year "; year; "at the"
picDisplay.Print "cost of"; cost; "is as follows:"
picDisplay.Print "The value after one year is:";
Do While cost > depreciation
cost = cost - depreciation
picDisplay.Print cost
Loop
End Sub
"I drink, therefore I am." -Rene Descartes
1) How do I do I print string info before each loop value? (eg.: "After two years"; value, "After three years"; value, etc.)
2) I'm losing the original value of "cost" because the first loop redifines it as zero. I tried putting "ByVal cost" in the click event and DoubleDeclining sub procedure but it didn't work.
3) DoubleDeclining needs to depreciate 2/nths of the new value every year, not depreciate the same amount every year.
Until the last year when it wipes out the remaing balance.
The user defines the number of years to be depreciated.
Option Explicit
Private Sub cmdCalculate_Click()
Dim item As String, year As String
Dim cost As Single, number As Integer
Dim depreciation As Single, n As Integer
Call InputData(item, year, cost, number)
Call StraightLine(item, year, cost, number, depreciation)
Call DoubleDeclining(item, year, cost, number, depreciation)
End Sub
Private Sub InputData(item As String, year As String, cost As Single, number As Integer)
item = txtItem.Text
year = txtYear.Text
number = Val(txtNumber.Text)
cost = Val(txtCost.Text)
End Sub
Private Sub StraightLine(item As String, year As String, cost As Single, number As Integer, depreciation As Single)
'Calculate Straight Line Depreciation
depreciation = cost * (1 * (1 / number))
picDisplay.Print "The Straight Line Depreciation Schedule for your"
picDisplay.Print item; ", purchased in the year "; year; " at the"
picDisplay.Print "cost of"; cost; "is as follows:"
picDisplay.Print "The value after one year is:";
Do While cost > 0
cost = cost - depreciation
picDisplay.Print cost
Loop
End Sub
Private Sub DoubleDeclining(item As String, year As String, cost As Single, number As Integer, depreciation As Single)
'Calculate Straight Line Depreciation
depreciation = cost * (1 * (2 / number))
picDisplay.Print "The Double Declining Balance Depreciation Schedule"
picDisplay.Print "for your "; item; ", purchased in the year "; year; "at the"
picDisplay.Print "cost of"; cost; "is as follows:"
picDisplay.Print "The value after one year is:";
Do While cost > depreciation
cost = cost - depreciation
picDisplay.Print cost
Loop
End Sub
"I drink, therefore I am." -Rene Descartes