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.
DDB# Function Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
' This example uses the DDB# function to return the depreciation of an asset
' for a specific period using the double declining balance method based on
' the asset's initial cost, salvage value, and the useful life of the asset.
' Note: To run this example you must use the FINANCE.QLB Quick library.
' The FINANCE.BI include file must also be present.
' $INCLUDE: 'FINANCE.BI'
CONST YEARMONTHS = 12
CONST DOLLARFORMAT$ = "$###,###,###.00"
DEFDBL A-Z
DIM Status AS INTEGER
CLS ' Clear the screen
PRINT "Assume you have a piece of expensive manufacturing equipment."
INPUT "Enter the original cost of the equipment"; Cost
PRINT
PRINT "Salvage value = asset value 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
YearsInLife = Life / YEARMONTHS
' Round up to a whole year.
IF YearsInLife <> INT(Life / YEARMONTHS) THEN
YearsInLife = INT(YearsInLife + 1)
END IF
PRINT
PRINT "For what year of the asset's life do you want to calculate ";
INPUT "depreciation "; DeprYear
DO WHILE Depr < YearsInLife AND DeprYear > YearsInLife
PRINT
PRINT "The year you enter must be at least 1, and not more than";
PRINT YearsInLife
INPUT "Reenter the year"; DeprYear
LOOP
' Calculate and format the results.
TotalDepreciation = Cost - SalvageVal
PeriodDepreciation = DDB#(Cost, SalvageVal, YearsInLife, DeprYear, Status)
MonthDepreciation = PeriodDepreciation / YEARMONTHS
Cost$ = FORMAT$(Cost, DOLLARFORMAT$)
SalvageVal$ = FORMAT$(SalvageVal, DOLLARFORMAT$)
TotalDepreciation$ = FORMAT$(TotalDepreciation, DOLLARFORMAT$)
PeriodDepreciation$ = FORMAT$(PeriodDepreciation, DOLLARFORMAT$)
MonthDepreciation$ = FORMAT$(MonthDepreciation, DOLLARFORMAT$)
' Examine Status to determine success or failure of DDB#.
IF Status THEN
' If unsuccessful, announce a problem.
PRINT
PRINT "There was an error in calculating depreciation."
ELSE
' If successful, display the results.
PRINT
PRINT "If the original cost of your equipment is "; Cost$
PRINT "and the salvage value of that equipment is "; SalvageVal$
PRINT "at the end of its"; Life; "month lifetime, the total "
PRINT "depreciation is "; TotalDepreciation$; ". "
PRINT
PRINT "The depreciation in year"; DeprYear; "is "; PeriodDepreciation$
PRINT "or "; MonthDepreciation$; " per month."
END IF