bas7ex.hlp (Topic list)
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.
Pmt# and PPmt# Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example uses the Pmt# function to determine the payment for a loan
'over a prescribed period, at a fixed annual percentage rate. It also uses
'the PPmt# function to determine what part of the payment is principal.
'The program subtracts the principal payment from the monthly payment to
'determine the interest part of the payment.
 
'Note: To run this example you must use a Quick library that includes the
'procedures contained in the financial function library file. The
'following include file must also be present.
 
'$INCLUDE: 'FINANC.BI'
 
CONST ENDPER = 0
CONST BEGINPER = 1
CONST DOLLARFORMAT$ = "$#,###.##     "
CONST PERCENTFORMAT$ = "##.##"
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 is your loan set up for"; Periods
PRINT
 
DO WHILE PaymentTypeString$ <> "B" AND PaymentTypeString$ <> "E"
    PRINT "Are your 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
 
'Calculate and format the monthly payment.
 
'Put APR in proper form.
IF APR > 1 THEN APR = APR / 100
 
Payment = ABS(-Pmt#(APR / 12, Periods, PresVal, FutrVal, PaymtType, St))
 
'Examine St to determine success of failure of any financial function.
IF St THEN
    'If unsuccessful, announce a problem.
    PRINT "There was an error in calculating the monthly payment."
ELSE
    'Display the calculate monthly payment.
    PRINT "Your monthly payment is ";
    PRINT USING DOLLARFORMAT$; Payment
    PRINT
    PRINT "Would you like a breakdown of the principal and interest by"
    PRINT "month for the entire period of the loan? ";
    DO WHILE Answer$ <> "Y" AND Answer$ <> "N"
        Answer$ = UCASE$(INPUT$(1))
    LOOP
    PRINT Answer$
    PRINT
    IF Answer$ = "Y" THEN
        CLS
        PRINT "Month", "Payment", "Principal", "Interest"
        PRINT
        FOR Per = 1 TO Periods
 
            'Calculate the principal part of the payment.
PrPmt = ABS(-PPmt#(APR / 12, Per, Periods, -PresVal, FutrVal, PaymtType, St))
 
            'Properly round the result.
            PrPmt = (INT((PrPmt + .005) * 100) / 100)
 
            'Calculate the interest part of the payment.
            IntPmt = Payment - PrPmt
 
            'Properly round the result.
            IntPmt = (INT((IntPmt + .005) * 100) / 100)
 
            'Examine St to determine success or failure.
            IF St THEN
                'If unsuccessful, announce a problem.
                PRINT "There was an error in calculating the interest or"
                PRINT "principal for period"; Per; "of your loan."
                END
            ELSE
                PRINT USING "###"; Per;
                PRINT TAB(15);
                PRINT USING DOLLARFORMAT$; Payment; PrPmt; IntPmt
            END IF
 
        NEXT Per
    END IF
END IF