Q(uick)BASIC Function: DDB#
Quick View
DDB#
Returns the depreciation of an asset for a specific period using the double-declining-balance method
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- DDB# (cost#, salvage#, life#, period#, status%)
Description/Parameter(s)
cost# | The initial cost of the asset. |
salvage# | The value at the end of the useful life of the asset. |
life# | The useful life of the asset. |
period# | The period for which asset depreciation is desired. |
status% | A variable that returns a value indicating calculation failure or success: 0 = success; 1 = failure. |
- The arguments life# and period# must use the same units. If life# is given in months, period# also must be given in months.
- The argument status% can be any variable that returns information about the success or failure of the calculation. The value of status% will be 0 if the calculation was successful, and 1 if it was not.
Usage Notes
- The double-declining balance-method computes depreciation at an accelerated rate. Depreciation is highest in the first period and decreases in successive periods.
- The formula for DDB# is described in the BASIC Language Reference manual.
Important
- To use DDB# in the QBX environment, use the FINANCER.QLB Quick library. To use DDB# outside the QBX environment, link your program with the appropriate FINANCxx.LIB file. Depending on the compiler options you chose when you installed BASIC, one or more of the following files will be available:
Filename Compiler options FINANCER.LIB 80x87 or emulator math; DOS or OS/2 real mode FINANCAR.LIB Alternate math; DOS or OS/2 real mode FINANCEP.LIB 80x87 or emulator math; OS/2 protected mode FINANCAP.LIB Alternate math; OS/2 protected mode - The FINANC.BI header file contains the necessary function declarations for DDB#.
- For more information on using libraries, see "Creating and Using Quick Libraries" and "Using LINK and LIB" in the BASIC Programmer's Guide.
Example
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 assets initial cost, salvage value, and the useful life of the asset.
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 FINANC.BI and FORMAT.BI include files must also be present.
'$INCLUDE: 'FINANC.BI'
'$INCLUDE: 'FORMAT.BI'
CONST YEARMONTHS = 12
CONST DOLLARFORMAT$ = "$###,###,###.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
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$ = FormatD$(Cost, DOLLARFORMAT$)
SalvageVal$ = FormatD$(SalvageVal, DOLLARFORMAT$)
TotalDepreciation$ = FormatD$(TotalDepreciation, DOLLARFORMAT$)
PeriodDepreciation$ = FormatD$(PeriodDepreciation, DOLLARFORMAT$)
MonthDepreciation$ = FormatD$(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