Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
SLN# Function Programming Example
◄Example► ◄Contents► ◄Index► ◄Back►
─────────────────────────────────────────────────────────────────────────────
'This example uses the SLN# function to return the straight-line depreciation
'of an asset for a single period of its useful life.
'Note: To run this example you must use a Quick library that includes the
'procedures contained in the date/time/format and financial function
'library files. The following include files must also be present.
'$INCLUDE: 'FINANC.BI'
'$INCLUDE: 'FORMAT.BI'
CONST YEARMONTHS = 12
CONST DOLLARFORMAT$ = "$#,###,##0.00"
DEFDBL A-Z
DIM Status AS INTEGER
CLS
PRINT "Assume you have a piece of expensive manufacturing equipment."
INPUT "Enter the original cost of the equipment"; Cost
PRINT
PRINT "Salvage value is the value of the asset at the end of its useful life."
INPUT "What is the salvage value of the equipment"; SalvageVal
PRINT
INPUT "What is the useful life of the equipment in months"; Life
IF Life < YEARMONTHS THEN
PRINT
PRINT "If the life is less than a year, it is not an asset."
INPUT "Reenter the useful life of the equipment in months"; Life
END IF
PRINT
YearsInLife = Life / YEARMONTHS
'Round up to a whole year.
IF YearsInLife <> INT(Life / YEARMONTHS) THEN
YearsInLife = INT(YearsInLife + 1)
END IF
'Calculate and format the results.
PeriodDepreciation = SLN#(Cost, SalvageVal, YearsInLife, Status)
'Examine Status to determine success or failure of SLN#.
IF Status THEN
'If unsuccessful, announce a problem.
PRINT "There was an error in calculating depreciation."
ELSE
'If successful calculate, format, and display the results.
TotalDepreciation = Cost - SalvageVal
MonthDepreciation = PeriodDepreciation / YEARMONTHS
Cost$ = FormatD$(Cost, DOLLARFORMAT$)
SalvageVal$ = FormatD$(SalvageVal, DOLLARFORMAT$)
TotalDepreciation$ = FormatD$(TotalDepreciation, DOLLARFORMAT$)
PeriodDepreciation$ = FormatD$(PeriodDepreciation, DOLLARFORMAT$)
MonthDepreciation$ = FormatD$(MonthDepreciation, DOLLARFORMAT$)
PRINT "If the original cost of your equipment is "; Cost$; ","
PRINT "and the salvage value of that equipment is "; SalvageVal$; ","
PRINT "the total depreciation at the end of its"; Life; "month lifetime "
PRINT "is "; TotalDepreciation$; ". "
PRINT
PRINT "The straight-line depreciation is "
PRINT PeriodDepreciation$; " per year, or"
PRINT MonthDepreciation$; " per month."
END IF