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.
FV# Function Programming Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
'This example uses the FV# function to return the future value of an
'investment. You are prompted to input required information.
'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 ENDPERIOD = 0
CONST BEGINPERIOD = 1
CONST DOLLARFORMAT$ = "$#,###,##0.00"
CONST PERCENTFORMAT$ = "##.00"
DEFDBL A-Z
DIM APR AS SINGLE
DIM PaymentType AS INTEGER, Status AS INTEGER
CLS
INPUT "Enter the expected annual percentage rate "; APR
PRINT
INPUT "How much do you plan to invest each month"; Payment
PRINT
DO WHILE PaymentTypeString$ <> "B" AND PaymentTypeString$ <> "E"
PRINT "Make payments at the beginning or end of the month? ";
PaymentTypeString$ = UCASE$(INPUT$(1))
LOOP
'Set up the correct payment type.
IF PaymentTypeString$ = "B" THEN
PaymentType = BEGINPERIOD
PRINT "Beginning"
ELSE
PaymentType = ENDPERIOD
PRINT "End"
END IF
PRINT
INPUT "How long, in months, do you expect to invest"; Period
PRINT
INPUT "What is the current value, if any, of this investment"; CurVal
PRINT
'Calculate and format the results.
'Put APR in proper form.
IF APR <= 1 THEN
PercentageRate$ = FORMATS$(APR * 100, PERCENTFORMAT$) + "%"
ELSE
PercentageRate$ = FORMATS$(APR, PERCENTFORMAT$) + "%"
APR = APR / 100
END IF
Payment$ = FormatD$(Payment, DOLLARFORMAT$)
CurValue$ = FormatD$(CurVal, DOLLARFORMAT$)
FutrVal = FV#(APR / 12, Period, -Payment, -CurVal, PaymentType, Status)
FutureValue$ = FormatD$(FutrVal, DOLLARFORMAT$)
'Examine Status to determine success of failure of FV#.
IF Status THEN
'If unsuccessful, announce a problem.
PRINT "There was an error in calculating the future value."
ELSE
'If successful, display the results.
PRINT
PRINT "At "; PercentageRate$; " interest, your "; Payment$; " per month"
IF PaymentType = BEGINPERIOD THEN
PRINT "(paid at the beginning of each month), "
ELSE
PRINT "(paid at the end of each month), "
END IF
IF CurVal > 0 THEN
PRINT "plus the "; CurValue$; " your investment is currently worth,"
END IF
PRINT "will be worth "; FutureValue$; " after"; Period; "months."
END IF