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.
IPmt# Function Programming Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
'This example uses the IPmt# function to calculate how much you will pay
'over the lifetime of a loan where all the payments are of equal value.
'Note: To run this example you must use a Quick library that includes the
'procedures contained in one of the financial function library files and
'the FORMATD$ function contained in one of the date/time/format function
'library files. The following include files must also be present.
'$INCLUDE: 'FINANC.BI'
'$INCLUDE: 'FORMAT.BI'
CONST ENDPER = 0
CONST BEGINPER = 1
CONST DOLLARFORMAT$ = "$###,###,###.00"
FutrVal = 0
DEFDBL A-Z
DIM St AS INTEGER
CLS
INPUT "Enter the annual percentage rate of your loan"; APR
PRINT
INPUT "What is the principal amount of your loan"; PresVal
PRINT
INPUT "How many monthly payments do you have to make"; Periods
PRINT
DO WHILE PaymentTypeString$ <> "B" AND PaymentTypeString$ <> "E"
PRINT "Are payments due at the beginning or end of the month? ";
PaymentTypeString$ = UCASE$(INPUT$(1))
LOOP
'Set up the correct payment type.
IF PaymentTypeString$ = "B" THEN
PaymtType = BEGINPER
PRINT "Beginning"
ELSE
PaymtType = ENDPER
PRINT "End"
END IF
PRINT
'Put APR in proper form.
IF APR > 1 THEN APR = APR / 100
FOR Per = 1 TO Periods
'Calculate the Interest paid each month.
IntPmt = ABS(IPmt#(APR / 12, Per, Periods, -PresVal, FutrVal, PaymtType, St))
'Check for an error.
IF St% THEN
PRINT "There was a calculation error."
END
END IF
'Accumulate a total.
TotalInterest = TotalInterest + IntPmt
NEXT Per
TotalInterest$ = FormatD$(TotalInterest, DOLLARFORMAT$)
PresentVal$ = FormatD$(PresVal, DOLLARFORMAT$)
TotalPaid$ = FormatD$(TotalInterest + PresVal, DOLLARFORMAT$)
PRINT
PRINT "You'll pay a total of "; TotalPaid$; " on your "; PresentVal$
PRINT "loan, of which "; TotalInterest$; " is interest."