home *** CD-ROM | disk | FTP | other *** search
/ On Hand / On_Hand_From_Softbank_1994_Release_2_Disc_2_1994.iso / 00202 / s / disk1 / loan.fr_ / loan.bin
Text File  |  1993-04-28  |  29KB  |  866 lines

  1. VERSION 2.00
  2. Begin Form LoanSheet 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "LoanSheet"
  5.    ClientHeight    =   5115
  6.    ClientLeft      =   1230
  7.    ClientTop       =   1845
  8.    ClientWidth     =   7065
  9.    ClipControls    =   0   'False
  10.    Height          =   5805
  11.    Icon            =   LOAN.FRX:0000
  12.    Left            =   1170
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    ScaleHeight     =   5115
  16.    ScaleWidth      =   7065
  17.    Top             =   1215
  18.    Width           =   7185
  19.    Begin CommandButton cmdCalcAmort 
  20.       Caption         =   "Show Amortization"
  21.       Enabled         =   0   'False
  22.       Height          =   375
  23.       Left            =   120
  24.       TabIndex        =   16
  25.       Top             =   4560
  26.       Width           =   2295
  27.    End
  28.    Begin CommandButton cmdCalcPmts 
  29.       Caption         =   "Show Payments"
  30.       Default         =   -1  'True
  31.       Height          =   375
  32.       Left            =   120
  33.       TabIndex        =   7
  34.       Top             =   4065
  35.       Width           =   2295
  36.    End
  37.    Begin Frame frmLoanLen 
  38.       Caption         =   "Years in Loan"
  39.       Height          =   1335
  40.       Left            =   120
  41.       TabIndex        =   13
  42.       Top             =   1200
  43.       Width           =   2295
  44.       Begin TextBox txtLenMax 
  45.          Height          =   285
  46.          Left            =   1440
  47.          TabIndex        =   3
  48.          Top             =   360
  49.          Width           =   615
  50.       End
  51.       Begin TextBox txtLenMin 
  52.          Height          =   285
  53.          Left            =   1440
  54.          TabIndex        =   4
  55.          Top             =   840
  56.          Width           =   615
  57.       End
  58.       Begin Label lblLen 
  59.          Caption         =   "Maximum"
  60.          Height          =   255
  61.          Index           =   0
  62.          Left            =   240
  63.          TabIndex        =   15
  64.          Top             =   390
  65.          Width           =   855
  66.       End
  67.       Begin Label lblLen 
  68.          Caption         =   "Minimum"
  69.          Height          =   255
  70.          Index           =   1
  71.          Left            =   240
  72.          TabIndex        =   14
  73.          Top             =   840
  74.          Width           =   855
  75.       End
  76.    End
  77.    Begin TextBox txtDwnPay 
  78.       Alignment       =   1  'Right Justify
  79.       Height          =   375
  80.       Left            =   1200
  81.       TabIndex        =   2
  82.       Top             =   720
  83.       Width           =   1215
  84.    End
  85.    Begin Grid grdPayments 
  86.       BackColor       =   &H00FFFFFF&
  87.       Cols            =   4
  88.       ForeColor       =   &H00000000&
  89.       Height          =   4815
  90.       HighLight       =   0   'False
  91.       Left            =   2655
  92.       Rows            =   17
  93.       ScrollBars      =   0  'None
  94.       TabIndex        =   11
  95.       Top             =   120
  96.       Width           =   4290
  97.    End
  98.    Begin Frame frmIntr 
  99.       Caption         =   "Interest Rates"
  100.       Height          =   1335
  101.       Left            =   120
  102.       TabIndex        =   8
  103.       Top             =   2640
  104.       Width           =   2295
  105.       Begin ComboBox comIntrMax 
  106.          Height          =   300
  107.          Left            =   1440
  108.          Style           =   2  'Dropdown List
  109.          TabIndex        =   5
  110.          Top             =   360
  111.          Width           =   735
  112.       End
  113.       Begin ComboBox comIntrMin 
  114.          Height          =   300
  115.          Left            =   1440
  116.          Style           =   2  'Dropdown List
  117.          TabIndex        =   6
  118.          Top             =   840
  119.          Width           =   735
  120.       End
  121.       Begin Label lblIntr 
  122.          Caption         =   "Minimum %"
  123.          Height          =   255
  124.          Index           =   1
  125.          Left            =   240
  126.          TabIndex        =   10
  127.          Top             =   885
  128.          Width           =   1095
  129.       End
  130.       Begin Label lblIntr 
  131.          Caption         =   "Maximum %"
  132.          Height          =   255
  133.          Index           =   0
  134.          Left            =   240
  135.          TabIndex        =   9
  136.          Top             =   405
  137.          Width           =   1095
  138.       End
  139.    End
  140.    Begin TextBox txtPurchTotl 
  141.       Alignment       =   1  'Right Justify
  142.       Height          =   375
  143.       Left            =   1200
  144.       TabIndex        =   1
  145.       Top             =   120
  146.       Width           =   1215
  147.    End
  148.    Begin Image imgGraphic 
  149.       Height          =   750
  150.       Left            =   1845
  151.       Picture         =   LOAN.FRX:0302
  152.       Top             =   165
  153.       Visible         =   0   'False
  154.       Width           =   750
  155.    End
  156.    Begin Label lblDwnPay 
  157.       Caption         =   "Percent Down"
  158.       Height          =   435
  159.       Left            =   120
  160.       TabIndex        =   12
  161.       Top             =   720
  162.       Width           =   900
  163.    End
  164.    Begin Label lblPurchTotl 
  165.       Caption         =   "Purchase Amount"
  166.       Height          =   435
  167.       Left            =   120
  168.       TabIndex        =   0
  169.       Top             =   120
  170.       Width           =   900
  171.    End
  172.    Begin Menu mnuOptions 
  173.       Caption         =   "&Options"
  174.       Begin Menu mnuOptCopy 
  175.          Caption         =   "&Copy"
  176.          Enabled         =   0   'False
  177.       End
  178.       Begin Menu mnuOptInstruct 
  179.          Caption         =   "&Instructions..."
  180.       End
  181.       Begin Menu mnuOptSep 
  182.          Caption         =   "-"
  183.       End
  184.       Begin Menu mnuOptExit 
  185.          Caption         =   "E&xit"
  186.       End
  187.    End
  188.    Begin Menu mnuDwnPay 
  189.       Caption         =   "&Down Payment"
  190.       Begin Menu mnuOptDwn 
  191.          Caption         =   "&Percent Down"
  192.          Checked         =   -1  'True
  193.          Index           =   0
  194.       End
  195.       Begin Menu mnuOptDwn 
  196.          Caption         =   "&Amount Down"
  197.          Index           =   1
  198.       End
  199.    End
  200.    Begin Menu mnuLoanLen 
  201.       Caption         =   "&Loan Length"
  202.       Begin Menu mnuOptLen 
  203.          Caption         =   "&Years"
  204.          Checked         =   -1  'True
  205.          Index           =   0
  206.       End
  207.       Begin Menu mnuOptLen 
  208.          Caption         =   "&Months"
  209.          Index           =   1
  210.       End
  211.    End
  212. End
  213. Option Explicit
  214. ' Form variables for purchase/down payment
  215. Dim PurchAmt
  216. Dim DPAmt
  217. ' Form variable for loan amount
  218. Dim LoanAmt
  219. ' Form variables for min/max loan length
  220. Dim LenMin
  221. Dim LenMax
  222. ' Form variables for min/max interest rate
  223. Dim IntrMin
  224. Dim IntrMax
  225. ' Dynamic array for payments
  226. Dim Payments()
  227. ' Form variables to track number of rows and columns
  228. Dim Periods
  229. Dim Rates
  230. ' Form variables for current interest rate/period values
  231. Dim Interest
  232. Dim Months
  233. ' Array for amortization information
  234. Dim AmortData()
  235. ' Form variable to hold payment for amortization calculation
  236. Dim AmortPmnt
  237. ' Form variable flag telling if the grid shows amortization
  238. Dim AmortFlag
  239.  
  240. Sub CalcAmort ()
  241.     ' Declare local variables
  242.     Dim Count
  243.     ' Save monthly payment from selected cell
  244.     AmortPmnt = Payments(grdPayments.Row, grdPayments.Col)
  245.     ' Save interest rate from selected row
  246.     Interest = Payments(grdPayments.Row, 0) / 1200
  247.     ' If the periods = years
  248.     If mnuOptLen(0).Checked = True Then
  249.         ' Make loan length loan match selected cell
  250.         Months = Payments(0, grdPayments.Col) * 12
  251.     Else
  252.         Months = Payments(0, grdPayments.Col)
  253.     End If
  254.     ' Size array holding amortization data
  255.     ReDim AmortData(Months, 3)
  256.     ' Save original loan amount to calculate remaining principal
  257.     AmortData(0, 1) = LoanAmt
  258.     ' For each month in loan period
  259.     For Count = 1 To Months
  260.         ' Calculate interest paid for current month
  261.         AmortData(Count, 2) = Int((AmortData(Count - 1, 1) * Interest + .005) * 100) / 100
  262.         ' Calculate remaining balance of principal
  263.         AmortData(Count, 1) = AmortData(Count - 1, 1) - AmortPmnt + AmortData(Count, 2)
  264.     Next Count
  265. End Sub
  266.  
  267. Sub CalcPmnts ()
  268.     ' Declare local variables
  269.     Dim RowData
  270.     Dim ColData
  271.     ' Calculate # of periods/interest rates to display
  272.     Periods = (LenMax - LenMin) + 1
  273.     Rates = ((IntrMax - IntrMin) * 2) + 1
  274.     ' Size array for payments
  275.     ReDim Payments(Rates + 1, Periods + 1)
  276.     ' Store row headings (rates) in array
  277.     For RowData = 1 To Rates
  278.         Payments(RowData, 0) = IntrMin + ((RowData - 1) / 2)
  279.     Next RowData
  280.     ' Store column headings (loan lengths) in array
  281.     For ColData = 1 To Periods
  282.         Payments(0, ColData) = LenMin + (ColData - 1)
  283.     Next ColData
  284.     ' If periods = years
  285.     If mnuOptLen(0).Checked = True Then
  286.         ' For each interest rate/loan length, calculate payments
  287.         For RowData = 1 To Rates
  288.             Interest = Val(Payments(RowData, 0)) / 1200
  289.             For ColData = 1 To Periods
  290.                 Months = Payments(0, ColData) * 12
  291.                 Payments(RowData, ColData) = MonthPay(Interest, Months)
  292.             Next ColData
  293.         Next RowData
  294.     ' If periods = months
  295.     Else
  296.         ' For each interest rate/loan length, calculate payments
  297.         For RowData = 1 To Rates
  298.             Interest = Val(Payments(RowData, 0)) / 1200
  299.             For ColData = 1 To Periods
  300.                 Months = Payments(0, ColData)
  301.                 Payments(RowData, ColData) = MonthPay(Interest, Months)
  302.             Next ColData
  303.         Next RowData
  304.     End If
  305. End Sub
  306.  
  307. Sub ClearGrid ()
  308.     ' Declare local variables
  309.     Dim Count As Integer
  310.     ' Clear text from 1st col
  311.     grdPayments.Col = 0
  312.     For Count = 1 To grdPayments.Rows - 1
  313.         grdPayments.Row = Count
  314.         grdPayments.Text = " "
  315.     Next Count
  316.     ' Clear text from 1st row
  317.     grdPayments.Row = 0
  318.     For Count = 1 To grdPayments.Cols - 1
  319.         grdPayments.Col = Count
  320.         grdPayments.Text = " "
  321.     Next Count
  322.     ' Clear text from non-fixed cells
  323.     grdPayments.SelStartCol = 1
  324.     grdPayments.SelStartRow = 1
  325.     grdPayments.SelEndCol = grdPayments.Cols - 1
  326.     grdPayments.SelEndRow = grdPayments.Rows - 1
  327.     grdPayments.FillStyle = 1
  328.     grdPayments.Text = ""
  329.     grdPayments.FillStyle = 0
  330.     grdPayments.SelEndCol = 1
  331.     grdPayments.SelEndRow = 1
  332. End Sub
  333.  
  334. Sub ClipCopy ()
  335.     ' Declare local variables
  336.     Dim ClipText
  337.     Dim CopyText
  338.     Dim NC
  339.     Dim NR
  340.     Dim Count
  341.     Dim ColStrt
  342.     Dim ColEnd
  343.     Dim RowStrt
  344.     Dim RowEnd
  345.     Dim HeadTxt
  346.     ' Initialize new column (NC) & row (NR) variables
  347.     NC = Chr$(9)
  348.     NR = Chr$(13) & Chr$(10)
  349.     ' Initialize variables for rows/cols selected
  350.     ColStrt = grdPayments.SelStartCol
  351.     ColEnd = grdPayments.SelEndCol
  352.     RowStrt = grdPayments.SelStartRow
  353.     RowEnd = grdPayments.SelEndRow
  354.     ' Initialize variable that gets input from grid
  355.     ClipText = grdPayments.Clip
  356.     ' Initialize variable that holds output to the clipboard
  357.     CopyText = ""
  358.     ' Header row = current row
  359.     grdPayments.Row = 0
  360.     ' For each cell in header row
  361.     For Count = ColStrt To ColEnd
  362.         ' Set current column
  363.         grdPayments.Col = Count
  364.         ' Does grid display payment or amortization info?
  365.         Select Case AmortFlag
  366.         ' If payments displayed
  367.         Case False
  368.             ' Is loan length in years or months?
  369.             Select Case mnuOptLen(0).Checked
  370.             ' If loan length = years
  371.             Case True
  372.                 HeadTxt = Payments(0, Count) & " Years"
  373.             ' If loan length = months
  374.             Case False
  375.                 HeadTxt = Payments(0, Count) & " Months"
  376.             End Select
  377.         ' If amortization info displayed
  378.         Case True
  379.             ' Define heading text
  380.             HeadTxt = Mid$(grdPayments.Text, 2, Len(grdPayments.Text) - 1)
  381.         End Select
  382.         ' Copy column header to output variable
  383.         CopyText = CopyText & NC & HeadTxt
  384.     Next Count
  385.     CopyText = CopyText & NR
  386.     ' Add 1st row header to output variable
  387.     grdPayments.Col = 0
  388.     grdPayments.Row = RowStrt
  389.     CopyText = CopyText & grdPayments.Text & NC
  390.     ' Copy text from input variable to output variable
  391.     For Count = 1 To Len(ClipText)
  392.         ' If current character isn't carriage return
  393.         If Mid$(ClipText, Count, 1) <> Chr$(13) Then
  394.             ' Concat character to output variable
  395.             CopyText = CopyText & Mid$(ClipText, Count, 1)
  396.         ' If current character is carriage return
  397.         Else
  398.             ' Concat carriage return/linefeed to output variable
  399.             grdPayments.Row = grdPayments.Row + 1
  400.             CopyText = CopyText & NR & grdPayments.Text & NC
  401.         End If
  402.     Next Count
  403.     ' Copy contents of output variable to clipboard
  404.     Clipboard.SetText CopyText
  405. End Sub
  406.  
  407. Sub cmdCalcAmort_Click ()
  408.     ' Change mouse pointer to hourglass
  409.     MousePointer = 11
  410.     ' Calculate amortization
  411.     CalcAmort
  412.     ' Display amortization
  413.     ShowAmort
  414.     ' Return mouse pointer to default
  415.     MousePointer = 0
  416. End Sub
  417.  
  418. Sub cmdCalcPmts_Click ()
  419.     ' Disable amortization button
  420.     cmdCalcAmort.Enabled = False
  421.     ' Does Purchase Amount have a value?
  422.     If PurchAmt <= 0 Then
  423.         MsgBox "You must enter a valid purchase amount.", 48, "LoanSheet Error"
  424.         txtPurchTotl.Text = ""
  425.         txtPurchTotl.SetFocus
  426.         Exit Sub
  427.     End If
  428.     ' Does Maximum Length of Loan have a value?
  429.     If txtLenMax.Text = "" Then
  430.         MsgBox "You must enter a maximum length of loan.", 48, "LoanSheet Error"
  431.         txtLenMax.SetFocus
  432.         Exit Sub
  433.     End If
  434.     ' If maximum loan length is less than minimum loan length...
  435.     If txtLenMax.Text <> "" And LenMax < LenMin Then
  436.         MsgBox "Maximum length of loan must be greater than the minimum length of loan.", 48, "LoanSheet Error"
  437.         txtLenMax.Text = ""
  438.         txtLenMax.SetFocus
  439.         Exit Sub
  440.     End If
  441.     ' If minimum loan length has no value, set equal to 1
  442.     If txtLenMin.Text = "" Then
  443.         MsgBox "The minimum length of loan must be one month or year.", 48, "LoanSheet Error"
  444.         txtLenMin.Text = "1"
  445.         LenMin = 1
  446.     End If
  447.     ' If maximum interest rate is less than minimum interest rate...
  448.     If IntrMax < IntrMin Then
  449.         MsgBox "Maximum interest rate must be greater than the minimum interest rate.", 48, "LoanSheet Error"
  450.         comIntrMax.SetFocus
  451.         Exit Sub
  452.     End If
  453.     ' Is maximum interest rate entered?
  454.     If IntrMax < .5 Then
  455.         MsgBox "You must specify a maximum interest rate greater than zero.", 48, "LoanSheet Error"
  456.         comIntrMax.SetFocus
  457.         Exit Sub
  458.     End If
  459.     ' If no minimum rate entered, min rate = max rate
  460.     If IntrMin < .5 Then
  461.         comIntrMin.ListIndex = comIntrMax.ListIndex
  462.         IntrMin = IntrMax
  463.     End If
  464.     ' Calculate loan amount
  465.     If mnuOptDwn(0).Checked = True Then
  466.         LoanAmt = PurchAmt * (1 - (DPAmt / 100))
  467.     ElseIf mnuOptDwn(1).Checked = True Then
  468.         LoanAmt = PurchAmt - DPAmt
  469.     End If
  470.     ' Change mouse pointer to hourglass
  471.     MousePointer = 11
  472.     ' Calculate payments for all loan lengths/interest rates
  473.     CalcPmnts
  474.     ' Display payments in grid
  475.     ShowPmnts
  476.     ' Change mouse pointer to default
  477.     MousePointer = 0
  478. End Sub
  479.  
  480. Sub comIntrMax_Click ()
  481.     IntrMax = Val(comIntrMax.Text)
  482.     ' If max interest is less than min interest
  483.     If IntrMax < IntrMin Then
  484.         MsgBox "Maximum interest rate must be greater than or equal to the minimum interest rate.", 48, "LoanSheet Error"
  485.         comIntrMax.ListIndex = comIntrMin.ListIndex
  486.         comIntrMax.SetFocus
  487.     End If
  488. End Sub
  489.  
  490. Sub comIntrMin_Click ()
  491.     IntrMin = Val(comIntrMin.Text)
  492.     ' If max interest is less than min interest
  493.     If IntrMax < IntrMin Then
  494.         MsgBox "Minimum interest rate must be less than or equal to the maximum interest rate.", 48, "LoanSheet Error"
  495.         comIntrMin.ListIndex = comIntrMin.ListIndex
  496.         comIntrMin.SetFocus
  497.     End If
  498. End Sub
  499.  
  500. Sub Form_Load ()
  501.     ' Declare local variables
  502.     Dim iRate
  503.     Dim Count
  504.     ' Set down payment to 0
  505.     DPAmt = 0
  506.     ' Put app in center of screen
  507.     LoanSheet.Left = (Screen.Width - LoanSheet.Width) / 2
  508.     LoanSheet.Top = (Screen.Height - LoanSheet.Height) / 2
  509.     ' Put allowed interest rates in list boxes
  510.     For iRate = 0 To 25 Step .5
  511.         comIntrMin.AddItem Format$(iRate, "0.0")
  512.         comIntrMax.AddItem Format$(iRate, "0.0")
  513.     Next iRate
  514.     ' Set interest rates 0.0
  515.     comIntrMin.ListIndex = 0
  516.     comIntrMax.ListIndex = 0
  517.     ' Put graphic in cell 0, 0
  518.     grdPayments.Row = 0
  519.     grdPayments.Col = 0
  520.     grdPayments.ColWidth(0) = imgGraphic.Width
  521.     grdPayments.RowHeight(0) = imgGraphic.Height
  522.     grdPayments.Picture = imgGraphic.Picture
  523.     ' Set default # of rates/periods
  524.     Rates = 16
  525.     Periods = 3
  526.     ' Set width of non-fixed cols
  527.     SizeCells grdPayments
  528. End Sub
  529.  
  530. Sub Form_Unload (Cancel As Integer)
  531.     End
  532. End Sub
  533.  
  534. Sub grdPayments_Click ()
  535.     ' Only act if cell contains a payment
  536.     If grdPayments.Text <> "" And AmortFlag = False Then
  537.         ' Enable amortization button
  538.         cmdCalcAmort.Enabled = True
  539.     Else
  540.         ' Disable amortization button
  541.         cmdCalcAmort.Enabled = False
  542.     End If
  543. End Sub
  544.  
  545. Sub grdPayments_DblClick ()
  546.     ' Only act if cell contains a payment
  547.     If grdPayments.Text <> "" And AmortFlag = False Then
  548.         ' Enable amortization button
  549.         cmdCalcAmort.Enabled = True
  550.         ' Change mouse pointer to hourglass
  551.         MousePointer = 11
  552.         ' Calculate amortization
  553.         CalcAmort
  554.         ' Display amortization
  555.         ShowAmort
  556.         ' Change mouse pointer to default
  557.         MousePointer = 0
  558.     Else
  559.         ' Disable amortization button
  560.         cmdCalcAmort.Enabled = False
  561.     End If
  562. End Sub
  563.  
  564. Sub mnuOptCopy_Click ()
  565.     ClipCopy
  566. End Sub
  567.  
  568. Sub mnuOptDwn_Click (Index As Integer)
  569.     Select Case Index
  570.         Case 0
  571.             mnuOptDwn(0).Checked = True
  572.             mnuOptDwn(1).Checked = False
  573.             lblDwnPay.Caption = "Percent Down"
  574.         Case 1
  575.             mnuOptDwn(0).Checked = False
  576.             mnuOptDwn(1).Checked = True
  577.             lblDwnPay.Caption = "Amount Down"
  578.     End Select
  579. End Sub
  580.  
  581. Sub mnuOptExit_Click ()
  582.     End
  583. End Sub
  584.  
  585. Sub mnuOptInstruct_Click ()
  586.     ' Declare local variables
  587.     Dim MsgText
  588.     Dim PB
  589.     ' Initialize paragraph break variable
  590.     PB = Chr$(10) & Chr$(13) & Chr$(10) & Chr$(13)
  591.     ' Display message
  592.     MsgText = "Enter purchase amount, down payment, length of loan, and interest rates. Click the Calculate Payments button to display monthly payments in the grid on the right."
  593.     MsgText = MsgText & PB & "Select a monthly payment and click the Calculate Amortization button to display an amortization schedule for the selected interest rate and length of loan in the grid."
  594.     MsgText = MsgText & PB & "Highlight cells in the grid and select Copy from the Options menu to copy data to the Clipboard."
  595.     MsgBox MsgText, 64, "LoanSheet Instructions"
  596. End Sub
  597.  
  598. Sub mnuOptLen_Click (Index As Integer)
  599.     Select Case Index
  600.         ' Loan length = years
  601.         Case 0
  602.             mnuOptLen(0).Checked = True
  603.             mnuOptLen(1).Checked = False
  604.             frmLoanLen.Caption = "Years in Loan"
  605.         ' Loan length = months
  606.         Case 1
  607.             mnuOptLen(0).Checked = False
  608.             mnuOptLen(1).Checked = True
  609.             frmLoanLen.Caption = "Months in Loan"
  610.     End Select
  611. End Sub
  612.  
  613. Function MonthPay (Interest, Months)
  614.     MonthPay = LoanAmt * (Interest / (1 - (1 / ((1 + Interest) ^ Months))))
  615. End Function
  616.  
  617. Sub ShowAmort ()
  618.     ' Declare local variables
  619.     Dim Count
  620.     Dim Row2Fill
  621.     Dim Col2Fill
  622.     Dim GridHgt
  623.     Dim GridWid
  624.     Dim NL
  625.     Dim IntrTotl
  626.     ' Clear contents of grid
  627.     ClearGrid
  628.     ' Initialize line break variable
  629.     NL = Chr$(10) & Chr$(13)
  630.     ' Set # of non-fixed cols (4)
  631.     grdPayments.Cols = 5
  632.     ' Replace picture in 0, 0 cell with text
  633.     grdPayments.Row = 0
  634.     grdPayments.Col = 0
  635.     grdPayments.Picture = LoadPicture()
  636.     grdPayments.Text = NL & "Payment" & NL & Format$(AmortPmnt, "Currency")
  637.     grdPayments.ColWidth(0) = 1.1 * TextWidth(grdPayments.Text)
  638.     ' Set remaining col headings
  639.     grdPayments.Col = 1
  640.     grdPayments.Text = NL & "Principal Paid"
  641.     grdPayments.Col = 2
  642.     grdPayments.Text = NL & "Interest Paid"
  643.     grdPayments.Col = 3
  644.     grdPayments.Text = NL & "Principal Balance"
  645.     grdPayments.Col = 4
  646.     grdPayments.Text = NL & "Total Interest"
  647.     ' Display vert scroll bar
  648.     grdPayments.ScrollBars = 3
  649.     ' Initialize variables for non-fixed height/width of grid less fixed
  650.     ' rows/cols and grid border (30).
  651.     GridHgt = grdPayments.Height - grdPayments.RowHeight(0) - 30
  652.     GridWid = grdPayments.Width - grdPayments.ColWidth(0) - 30
  653.     ' Set # of non-fixed rows
  654.     If Months > 16 Then
  655.         grdPayments.Rows = Months + 1
  656.     Else
  657.         grdPayments.Rows = 16
  658.     End If
  659.     ' 1st col = current column
  660.     grdPayments.Col = 0
  661.     ' Set row heights to evenly display 16 rows in non-fixed height and
  662.     ' show payment # in 1st col
  663.     For Count = 1 To Months
  664.         grdPayments.RowHeight(Count) = GridHgt / 16
  665.         grdPayments.Row = Count
  666.         grdPayments.Text = Count
  667.     Next Count
  668.     ' Set col widths to evenly display 2 columns in non-fixed width
  669.     ' less width of vert scroll bar.
  670.     For Count = 1 To 4
  671.         grdPayments.ColWidth(Count) = (GridWid - 255) / 2
  672.     Next Count
  673.     ' Set initial interest total
  674.     IntrTotl = 0
  675.     ' Put values of non-fixed rows in grid
  676.     For Row2Fill = 1 To Months
  677.         ' For each month in repayment period
  678.         grdPayments.Row = Row2Fill
  679.         ' Display part of payment applied to principal in 1st non-fixed col
  680.         grdPayments.Col = 1
  681.         grdPayments.Text = Format$(AmortPmnt - AmortData(Row2Fill, 2), "Currency")
  682.         ' Display interest paid this payment in 2nd non-fixed col
  683.         grdPayments.Col = 2
  684.         grdPayments.Text = Format$(AmortData(Row2Fill, 2), "Currency")
  685.         ' Display balance remaining on principal in 3rd non-fixed col
  686.         grdPayments.Col = 3
  687.         grdPayments.Text = Format$(AmortData(Row2Fill, 1), "Currency")
  688.         ' Display total interest paid to date in last non-fixed col
  689.         grdPayments.Col = 4
  690.         IntrTotl = IntrTotl + AmortData(Row2Fill, 2)
  691.         grdPayments.Text = Format$(IntrTotl, "Currency")
  692.     Next Row2Fill
  693.     ' Disable Calculate Amortization button
  694.     cmdCalcAmort.Enabled = False
  695.     ' Enable amortization flag
  696.     AmortFlag = True
  697. End Sub
  698.  
  699. Sub ShowPmnts ()
  700.     ' Declare local variables
  701.     Dim Row2Fill
  702.     Dim Col2Fill
  703.     Dim NL As String
  704.     Dim PeriodTxt As String
  705.     ' Clear grid contents
  706.     ClearGrid
  707.     ' Reset picture in cell 0, 0
  708.     grdPayments.Row = 0
  709.     grdPayments.Col = 0
  710.     grdPayments.Picture = imgGraphic.Picture
  711.     grdPayments.ColWidth(0) = imgGraphic.Width
  712.     ' Size non-fixed cells
  713.     SizeCells grdPayments
  714.     ' Initialize line break variable
  715.     NL = Chr$(10) & Chr$(13)
  716.     ' Initialize variable for loan period (years or months)
  717.     If mnuOptLen(0).Checked = True Then
  718.         PeriodTxt = "Years"
  719.     Else
  720.         PeriodTxt = "Months"
  721.     End If
  722.     ' 1st row = current row
  723.     grdPayments.Row = 0
  724.     ' Put col headings in 1st row
  725.     For Col2Fill = 1 To Periods
  726.         grdPayments.Col = Col2Fill
  727.         grdPayments.FixedAlignment(Col2Fill) = 2
  728.         grdPayments.Text = NL & Payments(0, Col2Fill) & NL & PeriodTxt
  729.     Next Col2Fill
  730.     ' Center text in 1st col
  731.     grdPayments.FixedAlignment(0) = 2
  732.     ' Put row headings in 1st col
  733.     grdPayments.Col = 0
  734.     For Row2Fill = 1 To Rates
  735.         grdPayments.Row = Row2Fill
  736.         grdPayments.Text = Format$(Payments(Row2Fill, 0), "0.0") & "%"
  737.     Next Row2Fill
  738.     ' Fill grid with payments from array
  739.     For Row2Fill = 1 To Rates
  740.         For Col2Fill = 1 To Periods
  741.             grdPayments.Row = Row2Fill
  742.             grdPayments.Col = Col2Fill
  743.             grdPayments.ColAlignment(Col2Fill) = 2
  744.             grdPayments.Text = Format$(Payments(Row2Fill, Col2Fill), "Currency")
  745.         Next Col2Fill
  746.     Next Row2Fill
  747.     ' Allow cell highlighting
  748.     grdPayments.HighLight = True
  749.     ' Enable copying from cells to clipboard
  750.     mnuOptCopy.Enabled = True
  751.     ' Set amortization flag to false
  752.     AmortFlag = False
  753. End Sub
  754.  
  755. Sub SizeCells (ThisGrid As Control)
  756.     ' Declare local variables
  757.     Dim Count
  758.     Dim GridHgt
  759.     Dim GridWid
  760.     Dim ScrollHgt
  761.     Dim ScrollWid
  762.     ' Initialize variables for non-fixed height/width of grid less
  763.     ' fixed row/column and grid border (30)
  764.     GridHgt = ThisGrid.Height - ThisGrid.RowHeight(0) - 30
  765.     GridWid = ThisGrid.Width - ThisGrid.ColWidth(0) - 30
  766.     ' Initialize variables for scroll bar height/width
  767.     ScrollHgt = 255
  768.     ScrollWid = 255
  769.     ' If data fits in default # of rows (16) and cols (3)
  770.     If Rates <= 16 And Periods <= 3 Then
  771.         ' Don't display scroll bars
  772.         ThisGrid.ScrollBars = 0
  773.         ' Set # of non-fixed rows/cols to default
  774.         ThisGrid.Rows = 17
  775.         ThisGrid.Cols = 4
  776.         ' Set row heights to evenly display 16 rows in non-fixed grid height
  777.         For Count = 1 To 16
  778.             ThisGrid.RowHeight(Count) = GridHgt / 16
  779.         Next Count
  780.         ' Set col widths to evenly display 3 columns in non-fixed grid width.
  781.         For Count = 1 To 3
  782.             ThisGrid.ColWidth(Count) = GridWid / 3
  783.         Next Count
  784.     ' If data needs more columns, but rows are OK
  785.     ElseIf Rates <= 16 And Periods > 3 Then
  786.         ' Display horiz scroll bar only
  787.         ThisGrid.ScrollBars = 1
  788.         ' Set # of non-fixed rows and cols
  789.         ThisGrid.Rows = 17
  790.         ThisGrid.Cols = Periods + 1
  791.         ' Set row heights to evenly display 16 rows in non-fixed grid height
  792.         ' minus scroll bar height
  793.         For Count = 1 To 16
  794.             ThisGrid.RowHeight(Count) = (GridHgt - ScrollHgt) / 16
  795.         Next Count
  796.         ' Set column widths to evenly display 3 columns in non-fixed grid width.
  797.         For Count = 1 To Periods
  798.             ThisGrid.ColWidth(Count) = GridWid / 3
  799.         Next Count
  800.     ' If data needs more rows, but cols are OK
  801.     ElseIf Rates > 16 And Periods <= 3 Then
  802.         ' Display vert scroll bar only
  803.         ThisGrid.ScrollBars = 2
  804.         ' Set number of non-fixed rows and cols
  805.         ThisGrid.Rows = Rates + 1
  806.         ThisGrid.Cols = 4
  807.         ' Set row heights to evenly display 16 rows in non-fixed grid height.
  808.         For Count = 1 To Rates
  809.             ThisGrid.RowHeight(Count) = GridHgt / 16
  810.         Next Count
  811.         ' Set col widths to evenly display 3 columns in non-fixed grid width
  812.         ' minus scroll bar width
  813.         For Count = 1 To 3
  814.             ThisGrid.ColWidth(Count) = (GridWid - ScrollWid) / 3
  815.         Next Count
  816.     ElseIf Rates > 16 And Periods > 3 Then
  817.         ' Display both scroll bars
  818.         ThisGrid.ScrollBars = 3
  819.         ' Set number of non-fixed rows/cols
  820.         ThisGrid.Rows = Rates + 1
  821.         ThisGrid.Cols = Periods + 1
  822.         ' Set row heights to evenly display 16 rows in non-fixed grid height
  823.         ' minus scroll bar height
  824.         For Count = 1 To Rates
  825.             ThisGrid.RowHeight(Count) = (GridHgt - ScrollHgt) / 16
  826.         Next Count
  827.         ' Set column widths to evenly display 3 columns in non-fixed grid width
  828.         ' minus scroll bar width
  829.         For Count = 1 To Periods
  830.             ThisGrid.ColWidth(Count) = (GridWid - ScrollWid) / 3
  831.         Next Count
  832.     End If
  833. End Sub
  834.  
  835. Sub txtDwnPay_Change ()
  836.     ' Store number into form variable
  837.     DPAmt = Val(txtDwnPay.Text)
  838.     ' Validate that DPAmt doesn't exceed 100% or Purchase Amount
  839.     If mnuOptDwn(0).Checked = True And DPAmt > 99 Then
  840.         MsgBox "Down payment percentage cannot exceed 99 percent.", 48, "LoanSheet Error"
  841.         txtDwnPay.Text = ""
  842.         txtDwnPay.SetFocus
  843.     ElseIf mnuOptDwn(1).Checked = True And DPAmt > PurchAmt Then
  844.         MsgBox "Down payment amount cannot exceed purchase amount.", 48, "LoanSheet Error"
  845.         txtDwnPay.Text = ""
  846.         txtDwnPay.SetFocus
  847.     ElseIf DPAmt < 0 Then
  848.         MsgBox "Down payment amount must be zero or greater.", 48, "LoanSheet Error"
  849.         txtDwnPay.Text = ""
  850.         txtDwnPay.SetFocus
  851.     End If
  852. End Sub
  853.  
  854. Sub txtLenMax_Change ()
  855.     LenMax = Val(txtLenMax.Text)
  856. End Sub
  857.  
  858. Sub txtLenMin_Change ()
  859.     LenMin = Val(txtLenMin.Text)
  860. End Sub
  861.  
  862. Sub txtPurchTotl_Change ()
  863.     PurchAmt = Val(txtPurchTotl.Text)
  864. End Sub
  865.  
  866.