| Home | Ruff-In | MTutor | GradientFill | FB code | FBLoan | TW-Form | JaxGUI | Other DownLoads | PBCC Code | GW Code | Fix 2000/ XP | Text Screen Shots | QB code
FB Loan

ConASCII

 
A Loan type program did in FreeBasic console mode 0

  

 

' FreeBasic code for a Loan program
'
' Use -lang deprecated   in compiler defaults
'
' Tested in Freebasic 20
'
' Screens and Buttons made with ConASCII
 
 
#define STD_OUTPUT_HANDLE &hfffffff5UL
 
Type wchar_t As uShort
 
Type CHAR As byte

Type WCHAR As wchar_t

Type PCHAR_INFO As CHAR_INFO ptr
 
Union CHAR_INFO_Char
   UnicodeChar As WCHAR
   AsciiChar As CHAR
End Union

Type CHAR_INFO
   Char As CHAR_INFO_Char
   Attributes As uShort       'WORD
End Type
 
Type SMALL_RECT
   left As Short
   Top As Short
   right As Short
   Bottom As Short
End Type
 
Type PSMALL_RECT As SMALL_RECT ptr
 
Type COORD
   X As Short
   Y As Short
End Type
 
Type HANDLE As Any ptr
 
Declare Function GetStdHandle alias "GetStdHandle" (ByVal As uInteger) As HANDLE

Declare Function ReadConsoleOutput alias "ReadConsoleOutputA" (ByVal As HANDLE, ByVal As PCHAR_INFO, _
                 ByVal As COORD, ByVal As COORD, ByVal As PSMALL_RECT) As Long
 
Declare Function WriteConsoleOutput alias "WriteConsoleOutputA" (ByVal As HANDLE, ByVal As CHAR_INFO ptr, _
                 ByVal As COORD, ByVal As COORD, ByVal As PSMALL_RECT) As Long

 Sub GetKeys (Keynumber As Integer, k As String, Rgt As Integer, _
              Lft As Integer,  cRow As Integer, cCol As Integer)
    dim buttons As Integer        
    Keynumber=0 : Rgt=0 : Lft=0 : cRow=0 : cCol=0 
    Locate 1, 1, 0  
    Do
        getmouse cCol, cRow,, buttons
        If buttons And 1 Then lft = 1 : Exit Sub
        If buttons And 2 Then Rgt = 1 : Exit Sub
        k = inkey$
        Sleep 1
    loop while k = ""
    If asc(k) > 31 And asc(k) < 127 Then
        keynumber = asc(k)
    ElseIf asc(k) = 27 Then
        keynumber = 27
    ElseIf asc(k) = 8 Then
        keynumber = 8
    ElseIf asc(k) = 9 Then
        keynumber = 9
    ElseIf asc(k) = 13 Then
        keynumber = 13   
    Else
        keynumber = cvi(k +k+ k+k) : Sleep 10                ' Fm Examples
    End If   
 End Sub
 
    
  Sub PCopys(Source As Integer, Dest As Integer)
      dim As Integer w = width
      dim As Integer row = w Shr 16, col = w And &HFFFF
      dim lpReadRegion As SMALL_RECT
      dim size As coord, ul As coord , buffer As String
      static As String sBuffer(100)
      lpReadRegion.right = col - 1
      lpReadRegion.Bottom = row - 1
      size.x = col+1 : size.y = row+1 : ul.x = 0 : ul.y = 0
      If Source = 1 Then
         sBuffer(Dest) = space$((row+1) * (col+1) * 4)
         ReadConsoleOutput GetStdHandle(STD_OUTPUT_HANDLE), _
             strptr(sBuffer(Dest)), size, ul, VarPtr(lpReadRegion)
      Else
         WriteConsoleOutput GetStdHandle(STD_OUTPUT_HANDLE), strptr(sBuffer(source)), _
                         size, ul,  VarPtr(lpReadRegion)
      End If                      
  End Sub
 
  
 Sub Putz( ByVal Lside As Long, ByVal Rside As Long, _
   ByVal Top As Long, ByVal Bottom As Long, scr As String) 
    dim lpReadRegion As SMALL_RECT, sBuffer As String 
    dim x As Long, y As Long, size As COORD, ul As COORD 
    For x = 1 to Len(scr)                                
      sBuffer = sBuffer & mid$(scr, X, 1) & Chr$(32)    
    Next x                         
    lpReadRegion.left = Lside - 1   
    lpReadRegion.right = Rside - 1   
    lpReadRegion.Top = Top - 1       
    lpReadRegion.Bottom = Bottom - 1 
    size.x = Rside + 1-Lside          
    size.y = Bottom + 1 - Top         
    ul.x = 0 : ul.y = 0                       'upper left
    WriteConsoleOutput GetStdHandle(STD_OUTPUT_HANDLE), strptr(sBuffer), _
                       size,  ul, VarPtr(lpReadRegion) 
 End Sub   
 
Sub  LOANSCREEN
  dim Scn As String
 Scn = " Ž ŽÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿x Ž Ž ŽÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿x Ž Ž" _
 + " Ž Ž³ pÚxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄx¿ p³x Ž Ž Ž³ ÚxÄxÄxÄx¿ xStetet xÚxÄxÄx¿ ³x Ž Ž" _
 + " Ž Ž³ p³x qÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿xÚxÄxÄxÄxÄx¿ q q q q q q q q q q³ p³x Ž Ž Ž³ ³x x x xÀÄxÄxÄxÄxÄxÙx x x³ ³x Ž Ž" _
 + " Ž Ž³ p³x q³ Nyuqmqbqeqrq qoqfq qPqaqyqmqeqnqtqsq qpqeqrq qYqeqaqrq q ³x³x x1v2v x³ q q q q q q q q q q³ p³x Ž Ž Ž³ ³x x x x x x x x x x x x x³ ³x Ž Ž" _
 + " Ž Ž³ p³x qÀÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÙxÀxÄÄÄÄÙ q q q q q q q q q q³ p³x Ž Ž Ž³ ³x xÚÄÄÄÄÄÄÄÄ¿x x³ ³x Ž Ž" _
 + " Ž Ž³ p³x qÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿xÚxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄx¿ q q q q q q q q q q³ p³x Ž Ž Ž³ ³x x³ T|otttatltst ³x x³ ³x Ž Ž" _
 + " Ž Ž³ p³x q³ Lqoqaqnq qAymqoquqnqtq     ³x³x x t t t t t t t t t t t t t t x x³ q q q q q q q q q q³ p³x Ž Ž Ž³ ³x xÀÄxÄxÄxÄxÄxÄxÄxÄxÙx x³ ³x Ž Ž" _
 + " Ž Ž³ p³x qÀÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÙxÀxÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ q q q q q q q q q q³ p³x Ž Ž Ž³ ³x xÚÄÄÄÄÄÄÄÄ¿x x³ ³x Ž Ž" _
 + " Ž Ž³ p³x qÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿xÚxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄx¿ q q q q q q q q q q q q q q³ p³x Ž Ž Ž³ ³x x³ L|otatnt   ³x x³ ³x Ž Ž" _
 + " Ž Ž³ p³x q³ Pyaqyqmqeqnqtq qAqmqoquqnqtq q ³x³x v t t t t t t t t t x t x³ q q q q q q q q q q q q q q³ p³x Ž Ž Ž³ ³x xÀÄxÄxÄxÄxÄxÄxÄxÄxÙx x³ ³x Ž Ž" _
 + " Ž Ž³ p³x qÀÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÙxÀxÄÄÄÄÄÄÄÄÄÄÄÄÄÙ q q q q q q q q q q q q q q³ p³x Ž Ž Ž³ ³x xÚÄÄÄÄÄÄÄÄ¿x x³ ³x Ž Ž" _
 + " Ž Ž³ p³x qÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿xÚxÄxÄxÄxÄxÄxÄx¿ q q q q q q q q q q q q q q q q q q q q q³ p³x Ž Ž Ž³ ³x x³  | t t t   ³x x³ ³x Ž Ž" _
 + " Ž Ž³ p³x q³ Iynqtqeqrqeqsqtq qRqaqtqeq q q ³x³x x t t x t x³ q q q q q q q q q q q q q q q q q q q q q³ p³x Ž Ž Ž³ ³x xÀÄxÄxÄxÄxÄxÄxÄxÄxÙx x³ ³x Ž Ž" _
 + " Ž Ž³ p³x qÀÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÙxÀxÄÄÄÄÄÄÙ q q q q q q q q q q q q q q q q q q q q q³ p³x Ž Ž Ž³ ³x xÚÄÄÄÄÄÄÄÄ¿x x³ ³x Ž Ž" _
 + " Ž Ž³ p³x qÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿xÚxÄxÄxÄxÄx¿ q qÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿xÚxÄxÄxÄxÄx¿ q³ p³x Ž Ž Ž³ ³x x³ Ptr|itnttt  ³x x³ ³x Ž Ž" _
 + " Ž Ž³ p³x q³ Nqrq.q qoqfq qYyeqaqrqsq q³x³x x t q x³ q q³ Nqrq.q qoqfq qMyoqnqtqhqsq q³x³x x t q x³ q³ p³x Ž Ž Ž³ ³x xÀÄxÄxÄxÄxÄxÄxÄxÄxÙx x³ ³x Ž Ž" _
 + " Ž Ž³ p³x qÀÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÙxÀxÄÄÄÄÙ q qÀÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÙxÀxÄÄÄÄÙ q³ p³x Ž Ž Ž³ ³x x x x x x x x x x x x x³ ³x Ž Ž" _
 + " Ž Ž³ p³x qÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿xÚxÄxÄxÄxÄx¿ÚxÄxÄxÄxÄx¿ÚxÄxÄxÄxÄxÄxÄx¿ q q q q q q q q q³ p³x Ž Ž Ž³ ÀxÄÄÄÄÄÄÄÄÄÄÄÄÙ ³x Ž Ž" _
 + " Ž Ž³ p³x q³ Dyaqtqeq qPqmqtq qSqtqaqrqtqsq q³x³x xMvMv x³³x xDvDv x³³x xYvYvYvYv x³ q q q q q q q q q³ p³x Ž Ž Ž³  x x x xÚÄÄÄÄÄÄ¿x x x ³x Ž Ž" _
 + " Ž Ž³ p³x qÀÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÙxÀxÄÄÄÄÙÀxÄÄÄÄÙÀxÄÄÄÄÄÄÙ q q q q q q q q q³ p³x Ž Ž Ž³  x x x x³ Etx|ittt v³x x x ³x Ž Ž" _
 + " Ž Ž³ pÀxÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ p³x Ž Ž Ž³  x x x xÀÄxÄxÄxÄxÄxÄxÙx x x ³x Ž Ž" _
 + " Ž ŽÀÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÙx Ž Ž ŽÀÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÙx Ž Ž" _
 + " Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž" _
 + " Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž" _
 + " Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž Ž"
    Putz  1, 80, 1, 25, Scn
End Sub

Sub  NROFPMT
  dim Scn As String
 Scn = "ÚxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄx¿" _
 + "³x xNyuymybyeyry yoyfy yPyayyymyeynytysy ypyeyry yYyeyayry x x³" _
 + "ÀxÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
    Putz  7, 38, 3, 5, Scn
End Sub

Sub  LOANAMT
  dim Scn As String
 Scn = "ÚxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄx¿" _
 + "³x xLyoyayny yAymyoyuynyty x x x x x³" _
 + "ÀxÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
    Putz  7, 25, 6, 8, Scn
End Sub

Sub  PAYAMT
  dim Scn As String
 Scn = "ÚxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄx¿" _
 + "³x xPyayyymyeynyty yAymyoyuynyty x x³" _
 + "ÀxÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
    Putz  7, 25, 9, 11, Scn
End Sub
 
Sub  INTERESTRATE
  dim Scn As String
 Scn = "ÚxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄx¿" _
 + "³x xIynytyeyryeysyty yRyaytyey x x x³" _
 + "ÀxÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
    Putz  7, 25, 12, 14, Scn
End Sub
 
Sub  NRYEARS
  dim Scn As String
 Scn = "ÚxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄx¿" _
 + "³x xNyry.y yoyfy yYyeyayrysy x³" _
 + "ÀxÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
    Putz  7, 22, 15, 17, Scn
End Sub

Sub  NRMONTHS
  dim Scn As String
 Scn = "ÚxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄx¿" _
 + "³x xNyry.y yoyfy yMyoynytyhysy x³" _
 + "ÀxÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
    Putz  31, 47, 15, 17, Scn
End Sub

Sub  DATESTART
  dim Scn As String
 Scn = "ÚxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄxÄx¿" _
 + "³x xDyaytyey yPymyty ySytyayrytysy x³" _
 + "ÀxÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
    Putz  7, 25, 18, 20, Scn
End Sub
 
Sub  TOTALS
  dim Scn As String
 Scn = "ÚxÄxÄxÄxÄxÄxÄxÄxÄx¿" _
 + "³x xT|o|t|a|l|s| x³" _
 + "ÀxÄÄÄÄÄÄÄÄÙ"
    Putz  65, 74, 5, 7, Scn
End Sub
 
Sub  YEAR
  dim Scn As String
 Scn = "ÚxÄxÄxÄxÄxÄxÄxÄxÄx¿" _
 + "³x xY|e|a|r| x x x³" _
 + "ÀxÄÄÄÄÄÄÄÄÙ"
  Putz  65, 74, 11, 13, Scn
End Sub
 
Sub  LOAN
  dim Scn As String
 Scn = "ÚxÄxÄxÄxÄxÄxÄxÄxÄx¿" _
 + "³x xL|o|a|n| x x x³" _
 + "ÀxÄÄÄÄÄÄÄÄÙ"
    Putz  65, 74, 8, 10, Scn
End Sub
 
Sub  PRINTs
  dim Scn As String
 Scn = "ÚxÄxÄxÄxÄxÄxÄxÄxÄx¿" _
 + "³x xP|r|i|n|t| x x³" _
 + "ÀxÄÄÄÄÄÄÄÄÙ"
    Putz  65, 74, 14, 16, Scn
End Sub

Sub  EXITS
  dim Scn As String
 Scn = "ÚxÄxÄxÄxÄxÄxÄx¿" _
 + "³x xE|x|i|t| x³" _
 + "ÀxÄÄÄÄÄÄÙ"
    Putz  67, 74, 19, 21, Scn
End Sub
                                   
 
 
 Sub Heading ()
     Print Tab(2); "NBR"; Tab(8); "DUE DATE"; Tab(21); "PMT AMT"; Tab(32); _
     "INTEREST"; Tab(42); "PRINCIPAL"; Tab(55); "BALANCE"; Tab(66); "YRLY INTEREST"
 End Sub 
 
 
 Sub blink (tx As String)
      dim x As Long
      color 7, 8
      For x = 1 to 20
          Locate 24, 3
          Print "                                                                               "
          Sleep 50
          Locate 24, 3
          Print tx
          Sleep 100
      Next x   
  End Sub  
 
 
   
 
 '------------------------------------------------------------------
 '               Routine to either Print the Loan to Screen or to Lpt1       
        
 
 Sub PrintLoan(L As Double, A As Double, I As Double, Nr As Long, _
               Mo As Long, m As Long, d As Long, y As Long, HotKey As String)
    dim As Double IL, INTS, yrINT, pr, LA, Istore,  Lstore, Astore, TOTIST
    dim As Long  nop, PmtNr, Mon, LF, Mstore, Dstore, Ystore, nops
    dim  As String Mn, Da, Ye, C, B, f
   
      
                                 ' Adjust formats to Loan
    If L < 1000 Then  
       B = "$$,###.##"        : c = "####"    : f = "$$##.##"
    ElseIf L < 10000 Then 
       B = "$$#,###.##"       : c = "####"   : f = "$$###.##"   
    ElseIf L < 100000 Then
       B = "$$##,###.##"      : c = "####"  : f = "$$#,###.##"
    ElseIf L > 100000 Then
       B = "$$###,###,###.##" : c = "####"  : f = "$$###,###.##" 
    End If
   
   
    Istore = I:  Lstore = L: Astore  = A : Mstore=m :Dstore = D : Ystore = Y   'store items
    I = I / nr
    IL = 0
    Locate 1, 1                               ' Print top for See Loan
    If HotKey = "L" Then
        Heading                              'CALL heading sub
        If PmtNr = 0 Then  Print Tab(55); : Print Using B; L: Print
    End If
    nops = 2
    For PmtNr = 1 to MO
         MON = M  :  LF = LF + 1
         If nop = 20  Then
             nop = 0
         End If
         nop = nop + 1
         If L > A Then                  ' If Loan > Payment amount, amortize it
            IL = I * L                  ' Get monthly interest
            pr = A - IL                 ' Get monthly principle
            L = L - pr                  ' Get monthly new balance
         Else
            IL = I * L                 ' Else if it isn't, Adjust last payment
            A  = L + IL                ' to what is actually owed.
            PR = A - IL
            A = PR + IL
            L = 0
         End If                                               
          
        If M > 9 Then Mn = str(M) Else Mn = "0" + str(M)        'Make Month Day  2 ditits
        If D > 9 Then Da = str(D) Else Da = "0" + str(D)        '
        Ye = str(Y)
      
    
        If HotKey = "R" Then                         ' Print Loan on LPT printer
          
           yrINT = yrINT + IL
            
           If PmtNr=1 Then LPrint "Pmt Nr   Date     Payment   Interest   Principle      Owed     Yrly Interest": LPrint
           LPrint Tab(1); : LPrint Using C; PmtNr; : LPrint Tab(8); Mn + "/" + Da + "/" + Ye;
           LPrint Tab(20); : LPrint Using f; A; : LPrint Tab(30); : LPrint Using f; IL;
           LPrint Tab(41);: LPrint Using f; PR; : LPrint Tab(55); : LPrint Using B; L;
           If M = 12 Or L = 0  Then LPrint Tab(66); : LPrint Using B; yrINT : yrINT = 0 :LPrint
          
       
                                                            
        ElseIf HotKey = "L" Then                                  '  see loan on screen
              
             nops =  nop + 2
           
             yrINT = yrINT + IL
           
             Locate Nops, 1  : Print Using C; PmtNr : Locate Nops, 8: Print Mn + "/" + Da + "/" + Ye
             Locate Nops, 21 : Print Using f; A : Locate Nops,32: Print Using f; IL               
             Locate Nops, 42 : Print Using f; PR : Locate Nops, 55 : Print Using B; L
             If M = 12 Or L = 0 Then Locate Nops, 68 : Print Using B; yrINT : yrINT = 0 : nop=nop+1
        End If
             
            
        If  HotKey = "L" And nop = 20 Then        
            LF = 0
            Locate 25, 2
            Print " Hit any Key to Continue.                                                 "
            Sleep
            Locate 1, 1
            cls
            Heading
        End If
       
         
        M = M + 1                                    ' Get Months and Years
        If M = 13 Then M = 1 : Y = Y + 1
        
        TOTIST = TOTIST + IL                         ' Add all interest for Total
    Next PmtNr
   
    If HotKey = "T" Or HotKey = "L" Then                            ' Print Totals to the screen
         If HotKey = "L" Then color 8, 7 Else color 7, 8
         Locate 24, 2     
         Print " Number of PMTS     DATE Paid       TOTAL Interest         TOTAL Payments    "
         Print Tab(6);: Print Using c; PmtNr-1;: Print Tab(22); Mn + "/" + Da + "/" + Ye;
         Print Tab(38);: Print Using B; TOTIST;: Print Tab(62);: Print Using B; Lstore+TOTIST
         If HotKey = "T" Then Sleep : Locate 10, 10 : Print "Hit any key to continue"
    ElseIf Hotkey = "R" Then
                                                   ' Print Totals on Paper
                
         LPrint " Amount Loaned           TOTAL Interest            TOTAL Payments     "
         LPrint Tab(5);: LPrint Using B; Lstore;: LPrint Tab(30);: LPrint Using B; TOTIST;
         LPrint Tab(56);: LPrint Using B; Lstore + TOTIST
         LPrint Chr(12)      ' Issue a formfeed
        
    End If
    
      
    If PmtNr > nr + 1 And HotKey = "L" Then Sleep
    I = Istore: L = Lstore: A = Astore : M = Mstore : D = Dstore : Y = Ystore       ' unstore em

 End Sub
                    
 
 '--------------------------------------------------------------------------------
                    '    M A I N     P R O G R A M
 '--------------------------------------------------------------------------------                  
 dim inputYear As String * 4
 dim dtInputStr As String * 2
 dim As String ch, InputStr, txt
 dim As Long Rt, Lt, Row, Col, Kn, Y, M, D,  Nr,   yr, mo, Mo1, x, z
 dim As Double LAmount, PAmount, IL, Interest, L1, hh, Ist
 dim As Double Inst, x1, x2, princ, I1
 
 Nr = 12                                   ' Default Nr of payments per year
 LoanScreen                                ' Display the screen 
 PCopys 1, 2 
 color 7, 8
 Locate 24, 3: Print "Hit the lighter colored Hotkey  or  Click on the Button with the mouse.    "
  
 Do
                                             ' Click on the Buttons or Hit the keys
   GetKeys Kn, ch, Rt, Lt, Row, Col
   ch = ucase$(ch)
  
   If ch="N" Or Lt <> 0 And Row>1 And Col>6 And Row<5 And Col<39 Then 'Nr of pmts per year
        '        
        NROFPMT : Sleep 200                                    ' Display sunken button
        Locate 24, 3: color 7, 8
        Print "Type in the number of Payments to make in a Year and then Hit the Enter Key"
        Locate 4, 41 : Print space$(2)
        Locate 4, 41 : line input InputStr : nr = val(InputStr) : If Nr = 0 Then Nr = 12
        PCopys 2, 1
          
   ElseIf ch="A" Or Lt <> 0 And Row>4 And Col>6 And Row<8 And Col<26 Then   'Loan Amount
        '      
        LOANAMT : Sleep 200                                           ' Display sunken button
        Locate 24, 3: color 7, 8
        Print "Type the amount that's being loaned and then Hit the Enter Key             "
        Locate 7, 28 : Print space$(15)
        Locate 7, 28 : line input InputStr : LAmount = val(InputStr) ' Get Loan Amount
        PCopys 2, 1 
       
   ElseIf ch="P" Or Lt <> 0 And Row>7 And Col>6 And Row<11 And Col<26 Then     'Payment Amount
        '         
        PAYAMT : Sleep 200                  ' Display sunken button
        Locate 24, 3: color 7, 8
        Print "Type the Payment Amount and Hit Enter                                      "
        Locate 10, 28 : Print space$(11)
        Locate 10, 28 : line input InputStr : PAmount = val(InputStr) ' Get Payment Amount
        PCopys 2, 1
        
   ElseIf ch="I" Or Lt <> 0 And Row>10 And Col>6 And Row<14 And Col<26 Then    'Interest Rate
        '        
        INTERESTRATE : Sleep 200             ' Display sunken button
        Locate 24, 3: color 7, 8
        Print "Type the Interest Rate and Hit Enter. Enter 10 for 10% or 25 for 25%,,ETC.."
        Locate 13, 28 : Print space$(4)
        Locate 13, 28 : line input InputStr : Interest = val("." + InputStr)
        PCopys 2, 1
          
   ElseIf ch="Y" Or Lt <> 0 And Row>13 And Col>6 And Row<17 And Col<23 Then     'Nr of Years
        If  Mo <> 0 Then Mo = mo1      
        NRYEARS  : Sleep 200                   ' Display sunken button
        Locate 24, 3: color 7, 8
        Print "Type the number of years the loan will last, and then hit Enter            "
        Locate 16, 25 : Print space$(2)
        Locate 16, 25 : line input InputStr : YR = val(InputStr)
        If  Mo<>0 Then Mo = mo1
        Mo = Mo + (YR * 12)
        PCopys 2, 1 
          
   ElseIf ch="M" Or Lt <> 0 And Row>13 And Col>31 And Row<17 And Col<48 Then     'Nr of Months
        '
        If Mo1 <> 0 Or Mo <> 0 Then Mo = Mo - Mo1
        NRMONTHS : Sleep 200                   ' Display sunken button
        Locate 24, 3: color 7, 8
        Print "Type the number of months in the Loan, and then hit Enter                  "
        Locate 16, 50 : Print space$(2)
        Locate 16, 50 : line input InputStr : MO = MO + val(InputStr)
        Mo1 = val(InputStr)
        PCopys 2, 1
          
   ElseIf ch="D" Or Lt <> 0 And Row>16 And Col>6 And Row<19 And Col<26 Then    'Date payment started
        '
           
        DATESTART : Sleep 200                  ' Display sunken button
        Locate 24, 3: color 7, 8
        Print "Type the Month the payment starts, and then hit Enter                      "
        Locate 19, 28 : line input dtInputStr : M = val(dtInputStr)         'Get start Month
        Locate 24, 3: color 7, 8
        Print "Type the Day the payment starts from 1st to the 28th, and then hit Enter   "
        Locate 19, 34 : line input dtInputStr : D = val(dtInputStr)         'Get start Day
        Locate 24, 3: color 7, 8
        Print "Type the Year the payment starts, and then hit Enter                       "
        Locate 19, 40 : line input InputYear : Y = val(InputYear)         'Get start Year
       
        PCopys 2, 1
          
   ElseIf ch="X" Or Lt <> 0 And Row>17 And Col>66 And Row<21 And Col<75 Then      ' E X I T
        '
        EXITS : Sleep 200 : End 
       
          
  '----------------------------------------------------------------------
  '               If all blanks are filled, make right menu available
  
   ElseIf  Mo<>0 Or yr<>0 And y<>0 And Interest<>0 And PAmount<>0 And LAmount<>0 Then  ' If all is filled
     
      If ch="T" Or Lt <> 0 And Row>3 And Col>64 And Row<7 And Col<75 Then        ' See Totals
          '       
          TOTALS : Sleep 200              ' Display sunken button 
         
          ch = "T"                      ' Needed If you used mouse
          PrintLoan lAmount, pAmount, Interest, Nr, Mo, m, d, y, ch
          PCopys 2, 1
            

      ElseIf ch="L" Or Lt <> 0 And Row>7 And Col>64 And Row<11 And Col<75 Then     ' See Loan
          '
          Loan : Sleep 200                ' Display sunken button
          cls
          ch = "L"                      ' Only needed if mouse used
          PrintLoan lAmount, pAmount, Interest, Nr, Mo, m, d, y, ch
          PCopys 2, 1 
            
      ElseIf ch="R" Or Lt <> 0 And Row>12 And Col>64 And Row<16 And Col<75 Then     ' Print Loan 
          '
           PRINTS : Sleep 200              ' Display sunken button
           ch = "R"
           PrintLoan lAmount, pAmount, Interest, Nr, Mo, m, d, y, ch
          PCopys 2, 1
                
      End If
   End If
                                                       
 '----------------------------------------------------------- Fill in the Blanks
   If LAmount = 0 And PAmount<>0 And Interest<>0 And MO<>0 Then         ' If Loan Amount is blank
       ' 
       LAmount = PAmount * ((1 - (1 / ((1 + (Interest/ nr)) ^ MO))) / (Interest / nr))
 
   ElseIf PAmount = 0 And LAmount<>0 And Interest<>0 And MO<>0 Then     ' If Payment Amount is Blank
       ' 
       PAmount=LAmount*((Interest / nr)/(1-(1+(Interest/nr)) ^ (-MO)))
   ElseIf Interest = 0 And LAmount<>0 And PAmount<>0 And MO<>0 Then       ' If Interest rate is Blank
       ' 
       Locate 23, 1: Print  lamount, pamount, mo
       IST = .5: x1 = 0: x2 = 1 : hh = 0 : inst = 0
       Do
            inst = (LAmount * IST) / (PAmount * nr) - 1 + (1 / ((1 + (IST / nr)) ^ (MO)))
            If abs(abs(inst) - 1E-10) < 5E-10 Then Exit Do
            If inst > 0 Then
                x2 = IST
            ElseIf hh = inst Then
               IST = 1
               Exit Do
            Else
               hh = inst: x1 = IST
            End If
            IST = (x1 + x2) / 2
       loop
       '       
       Interest = (int(IST * 100 + .5)) / 100
       If Interest > 500 Then
           txt = "Decrease the Number of Years or Payment amount to decrease the Interest    "
           blink txt
           interest = 0
       End If 
     
   ElseIf Yr=0 And Mo=0 And Interest<>0 And LAmount<>0 And PAmount<>0 Then  'blank years and months
      '
       L1 = LAmount : I1 = Interest              ' put it in temps
       I1 = I1  / nr
       while L1 > 0
          IL = I1 * L1
          Princ = pAmount - IL
          L1 = L1 - princ
         
          If IL > pAmount Then
              txt = " You'll have to either decrease Interest or Loan amount or increase Payment."
              blink txt
              Exit while 
          End If
          Mo = Mo + 1                    ' count the months
       Wend
                 
       If Mo > 12 Then
          Yr = int(Mo / 12) : Mo1 = Mo Mod 12    ' seperate years and months
       Else
          Mo1 = Mo
       End If                     
       
   End If
  
   '-------------------------------------------------------------- P R I N T  it on the screen
   color 0, 7
   If nr <> 12 Then Locate 4, 40 : Print nr
   If LAmount Then Locate 7, 28 : Print Using "$$#,####.##"; LAmount
   If pAmount Then Locate 10, 28 : Print Using "$$#,####.##"; pAmount
   If Interest Then Locate 13, 27 : Print Using "###.#"; (Interest*100); : ? "%"
   If yr Then Locate 16, 24 : Print int(yr)
   If mo1 Then Locate 16, 49 : Print mo1
   If M <> 0 Then
      Locate 19, 28
      If M > 9 Then  Print str(M) Else Print "0" + str(M)        'Make Month Day  2 ditits 
   End If
   If D <> 0 Then
      Locate 19, 34
      If D > 9 Then Print str(D) Else Print "0" + str(D)
   End If
   If Y <> 0 Then Locate 19, 40 : Print str(Y)
 
  
 loop Until Kn = 27