home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l405 / 1.ddi / LOAN.FR_ / LOAN.bin (.txt)
Encoding:
Visual Basic Form  |  1993-04-28  |  28.3 KB  |  839 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. Option Explicit
  213. ' Form variables for purchase/down payment
  214. Dim PurchAmt
  215. Dim DPAmt
  216. ' Form variable for loan amount
  217. Dim LoanAmt
  218. ' Form variables for min/max loan length
  219. Dim LenMin
  220. Dim LenMax
  221. ' Form variables for min/max interest rate
  222. Dim IntrMin
  223. Dim IntrMax
  224. ' Dynamic array for payments
  225. Dim Payments()
  226. ' Form variables to track number of rows and columns
  227. Dim Periods
  228. Dim Rates
  229. ' Form variables for current interest rate/period values
  230. Dim Interest
  231. Dim Months
  232. ' Array for amortization information
  233. Dim AmortData()
  234. ' Form variable to hold payment for amortization calculation
  235. Dim AmortPmnt
  236. ' Form variable flag telling if the grid shows amortization
  237. Dim AmortFlag
  238. Sub CalcAmort ()
  239.     ' Declare local variables
  240.     Dim Count
  241.     ' Save monthly payment from selected cell
  242.     AmortPmnt = Payments(grdPayments.Row, grdPayments.Col)
  243.     ' Save interest rate from selected row
  244.     Interest = Payments(grdPayments.Row, 0) / 1200
  245.     ' If the periods = years
  246.     If mnuOptLen(0).Checked = True Then
  247.         ' Make loan length loan match selected cell
  248.         Months = Payments(0, grdPayments.Col) * 12
  249.     Else
  250.         Months = Payments(0, grdPayments.Col)
  251.     End If
  252.     ' Size array holding amortization data
  253.     ReDim AmortData(Months, 3)
  254.     ' Save original loan amount to calculate remaining principal
  255.     AmortData(0, 1) = LoanAmt
  256.     ' For each month in loan period
  257.     For Count = 1 To Months
  258.         ' Calculate interest paid for current month
  259.         AmortData(Count, 2) = Int((AmortData(Count - 1, 1) * Interest + .005) * 100) / 100
  260.         ' Calculate remaining balance of principal
  261.         AmortData(Count, 1) = AmortData(Count - 1, 1) - AmortPmnt + AmortData(Count, 2)
  262.     Next Count
  263. End Sub
  264. Sub CalcPmnts ()
  265.     ' Declare local variables
  266.     Dim RowData
  267.     Dim ColData
  268.     ' Calculate # of periods/interest rates to display
  269.     Periods = (LenMax - LenMin) + 1
  270.     Rates = ((IntrMax - IntrMin) * 2) + 1
  271.     ' Size array for payments
  272.     ReDim Payments(Rates + 1, Periods + 1)
  273.     ' Store row headings (rates) in array
  274.     For RowData = 1 To Rates
  275.         Payments(RowData, 0) = IntrMin + ((RowData - 1) / 2)
  276.     Next RowData
  277.     ' Store column headings (loan lengths) in array
  278.     For ColData = 1 To Periods
  279.         Payments(0, ColData) = LenMin + (ColData - 1)
  280.     Next ColData
  281.     ' If periods = years
  282.     If mnuOptLen(0).Checked = True Then
  283.         ' For each interest rate/loan length, calculate payments
  284.         For RowData = 1 To Rates
  285.             Interest = Val(Payments(RowData, 0)) / 1200
  286.             For ColData = 1 To Periods
  287.                 Months = Payments(0, ColData) * 12
  288.                 Payments(RowData, ColData) = MonthPay(Interest, Months)
  289.             Next ColData
  290.         Next RowData
  291.     ' If periods = months
  292.     Else
  293.         ' For each interest rate/loan length, calculate payments
  294.         For RowData = 1 To Rates
  295.             Interest = Val(Payments(RowData, 0)) / 1200
  296.             For ColData = 1 To Periods
  297.                 Months = Payments(0, ColData)
  298.                 Payments(RowData, ColData) = MonthPay(Interest, Months)
  299.             Next ColData
  300.         Next RowData
  301.     End If
  302. End Sub
  303. Sub ClearGrid ()
  304.     ' Declare local variables
  305.     Dim Count As Integer
  306.     ' Clear text from 1st col
  307.     grdPayments.Col = 0
  308.     For Count = 1 To grdPayments.Rows - 1
  309.         grdPayments.Row = Count
  310.         grdPayments.Text = " "
  311.     Next Count
  312.     ' Clear text from 1st row
  313.     grdPayments.Row = 0
  314.     For Count = 1 To grdPayments.Cols - 1
  315.         grdPayments.Col = Count
  316.         grdPayments.Text = " "
  317.     Next Count
  318.     ' Clear text from non-fixed cells
  319.     grdPayments.SelStartCol = 1
  320.     grdPayments.SelStartRow = 1
  321.     grdPayments.SelEndCol = grdPayments.Cols - 1
  322.     grdPayments.SelEndRow = grdPayments.Rows - 1
  323.     grdPayments.FillStyle = 1
  324.     grdPayments.Text = ""
  325.     grdPayments.FillStyle = 0
  326.     grdPayments.SelEndCol = 1
  327.     grdPayments.SelEndRow = 1
  328. End Sub
  329. Sub ClipCopy ()
  330.     ' Declare local variables
  331.     Dim ClipText
  332.     Dim CopyText
  333.     Dim NC
  334.     Dim NR
  335.     Dim Count
  336.     Dim ColStrt
  337.     Dim ColEnd
  338.     Dim RowStrt
  339.     Dim RowEnd
  340.     Dim HeadTxt
  341.     ' Initialize new column (NC) & row (NR) variables
  342.     NC = Chr$(9)
  343.     NR = Chr$(13) & Chr$(10)
  344.     ' Initialize variables for rows/cols selected
  345.     ColStrt = grdPayments.SelStartCol
  346.     ColEnd = grdPayments.SelEndCol
  347.     RowStrt = grdPayments.SelStartRow
  348.     RowEnd = grdPayments.SelEndRow
  349.     ' Initialize variable that gets input from grid
  350.     ClipText = grdPayments.Clip
  351.     ' Initialize variable that holds output to the clipboard
  352.     CopyText = ""
  353.     ' Header row = current row
  354.     grdPayments.Row = 0
  355.     ' For each cell in header row
  356.     For Count = ColStrt To ColEnd
  357.         ' Set current column
  358.         grdPayments.Col = Count
  359.         ' Does grid display payment or amortization info?
  360.         Select Case AmortFlag
  361.         ' If payments displayed
  362.         Case False
  363.             ' Is loan length in years or months?
  364.             Select Case mnuOptLen(0).Checked
  365.             ' If loan length = years
  366.             Case True
  367.                 HeadTxt = Payments(0, Count) & " Years"
  368.             ' If loan length = months
  369.             Case False
  370.                 HeadTxt = Payments(0, Count) & " Months"
  371.             End Select
  372.         ' If amortization info displayed
  373.         Case True
  374.             ' Define heading text
  375.             HeadTxt = Mid$(grdPayments.Text, 2, Len(grdPayments.Text) - 1)
  376.         End Select
  377.         ' Copy column header to output variable
  378.         CopyText = CopyText & NC & HeadTxt
  379.     Next Count
  380.     CopyText = CopyText & NR
  381.     ' Add 1st row header to output variable
  382.     grdPayments.Col = 0
  383.     grdPayments.Row = RowStrt
  384.     CopyText = CopyText & grdPayments.Text & NC
  385.     ' Copy text from input variable to output variable
  386.     For Count = 1 To Len(ClipText)
  387.         ' If current character isn't carriage return
  388.         If Mid$(ClipText, Count, 1) <> Chr$(13) Then
  389.             ' Concat character to output variable
  390.             CopyText = CopyText & Mid$(ClipText, Count, 1)
  391.         ' If current character is carriage return
  392.         Else
  393.             ' Concat carriage return/linefeed to output variable
  394.             grdPayments.Row = grdPayments.Row + 1
  395.             CopyText = CopyText & NR & grdPayments.Text & NC
  396.         End If
  397.     Next Count
  398.     ' Copy contents of output variable to clipboard
  399.     Clipboard.SetText CopyText
  400. End Sub
  401. Sub cmdCalcAmort_Click ()
  402.     ' Change mouse pointer to hourglass
  403.     MousePointer = 11
  404.     ' Calculate amortization
  405.     CalcAmort
  406.     ' Display amortization
  407.     ShowAmort
  408.     ' Return mouse pointer to default
  409.     MousePointer = 0
  410. End Sub
  411. Sub cmdCalcPmts_Click ()
  412.     ' Disable amortization button
  413.     cmdCalcAmort.Enabled = False
  414.     ' Does Purchase Amount have a value?
  415.     If PurchAmt <= 0 Then
  416.         MsgBox "You must enter a valid purchase amount.", 48, "LoanSheet Error"
  417.         txtPurchTotl.Text = ""
  418.         txtPurchTotl.SetFocus
  419.         Exit Sub
  420.     End If
  421.     ' Does Maximum Length of Loan have a value?
  422.     If txtLenMax.Text = "" Then
  423.         MsgBox "You must enter a maximum length of loan.", 48, "LoanSheet Error"
  424.         txtLenMax.SetFocus
  425.         Exit Sub
  426.     End If
  427.     ' If maximum loan length is less than minimum loan length...
  428.     If txtLenMax.Text <> "" And LenMax < LenMin Then
  429.         MsgBox "Maximum length of loan must be greater than the minimum length of loan.", 48, "LoanSheet Error"
  430.         txtLenMax.Text = ""
  431.         txtLenMax.SetFocus
  432.         Exit Sub
  433.     End If
  434.     ' If minimum loan length has no value, set equal to 1
  435.     If txtLenMin.Text = "" Then
  436.         MsgBox "The minimum length of loan must be one month or year.", 48, "LoanSheet Error"
  437.         txtLenMin.Text = "1"
  438.         LenMin = 1
  439.     End If
  440.     ' If maximum interest rate is less than minimum interest rate...
  441.     If IntrMax < IntrMin Then
  442.         MsgBox "Maximum interest rate must be greater than the minimum interest rate.", 48, "LoanSheet Error"
  443.         comIntrMax.SetFocus
  444.         Exit Sub
  445.     End If
  446.     ' Is maximum interest rate entered?
  447.     If IntrMax < .5 Then
  448.         MsgBox "You must specify a maximum interest rate greater than zero.", 48, "LoanSheet Error"
  449.         comIntrMax.SetFocus
  450.         Exit Sub
  451.     End If
  452.     ' If no minimum rate entered, min rate = max rate
  453.     If IntrMin < .5 Then
  454.         comIntrMin.ListIndex = comIntrMax.ListIndex
  455.         IntrMin = IntrMax
  456.     End If
  457.     ' Calculate loan amount
  458.     If mnuOptDwn(0).Checked = True Then
  459.         LoanAmt = PurchAmt * (1 - (DPAmt / 100))
  460.     ElseIf mnuOptDwn(1).Checked = True Then
  461.         LoanAmt = PurchAmt - DPAmt
  462.     End If
  463.     ' Change mouse pointer to hourglass
  464.     MousePointer = 11
  465.     ' Calculate payments for all loan lengths/interest rates
  466.     CalcPmnts
  467.     ' Display payments in grid
  468.     ShowPmnts
  469.     ' Change mouse pointer to default
  470.     MousePointer = 0
  471. End Sub
  472. Sub comIntrMax_Click ()
  473.     IntrMax = Val(comIntrMax.Text)
  474.     ' If max interest is less than min interest
  475.     If IntrMax < IntrMin Then
  476.         MsgBox "Maximum interest rate must be greater than or equal to the minimum interest rate.", 48, "LoanSheet Error"
  477.         comIntrMax.ListIndex = comIntrMin.ListIndex
  478.         comIntrMax.SetFocus
  479.     End If
  480. End Sub
  481. Sub comIntrMin_Click ()
  482.     IntrMin = Val(comIntrMin.Text)
  483.     ' If max interest is less than min interest
  484.     If IntrMax < IntrMin Then
  485.         MsgBox "Minimum interest rate must be less than or equal to the maximum interest rate.", 48, "LoanSheet Error"
  486.         comIntrMin.ListIndex = comIntrMin.ListIndex
  487.         comIntrMin.SetFocus
  488.     End If
  489. End Sub
  490. Sub Form_Load ()
  491.     ' Declare local variables
  492.     Dim iRate
  493.     Dim Count
  494.     ' Set down payment to 0
  495.     DPAmt = 0
  496.     ' Put app in center of screen
  497.     LoanSheet.Left = (Screen.Width - LoanSheet.Width) / 2
  498.     LoanSheet.Top = (Screen.Height - LoanSheet.Height) / 2
  499.     ' Put allowed interest rates in list boxes
  500.     For iRate = 0 To 25 Step .5
  501.         comIntrMin.AddItem Format$(iRate, "0.0")
  502.         comIntrMax.AddItem Format$(iRate, "0.0")
  503.     Next iRate
  504.     ' Set interest rates 0.0
  505.     comIntrMin.ListIndex = 0
  506.     comIntrMax.ListIndex = 0
  507.     ' Put graphic in cell 0, 0
  508.     grdPayments.Row = 0
  509.     grdPayments.Col = 0
  510.     grdPayments.ColWidth(0) = imgGraphic.Width
  511.     grdPayments.RowHeight(0) = imgGraphic.Height
  512.     grdPayments.Picture = imgGraphic.Picture
  513.     ' Set default # of rates/periods
  514.     Rates = 16
  515.     Periods = 3
  516.     ' Set width of non-fixed cols
  517.     SizeCells grdPayments
  518. End Sub
  519. Sub Form_Unload (Cancel As Integer)
  520.     End
  521. End Sub
  522. Sub grdPayments_Click ()
  523.     ' Only act if cell contains a payment
  524.     If grdPayments.Text <> "" And AmortFlag = False Then
  525.         ' Enable amortization button
  526.         cmdCalcAmort.Enabled = True
  527.     Else
  528.         ' Disable amortization button
  529.         cmdCalcAmort.Enabled = False
  530.     End If
  531. End Sub
  532. Sub grdPayments_DblClick ()
  533.     ' Only act if cell contains a payment
  534.     If grdPayments.Text <> "" And AmortFlag = False Then
  535.         ' Enable amortization button
  536.         cmdCalcAmort.Enabled = True
  537.         ' Change mouse pointer to hourglass
  538.         MousePointer = 11
  539.         ' Calculate amortization
  540.         CalcAmort
  541.         ' Display amortization
  542.         ShowAmort
  543.         ' Change mouse pointer to default
  544.         MousePointer = 0
  545.     Else
  546.         ' Disable amortization button
  547.         cmdCalcAmort.Enabled = False
  548.     End If
  549. End Sub
  550. Sub mnuOptCopy_Click ()
  551.     ClipCopy
  552. End Sub
  553. Sub mnuOptDwn_Click (Index As Integer)
  554.     Select Case Index
  555.         Case 0
  556.             mnuOptDwn(0).Checked = True
  557.             mnuOptDwn(1).Checked = False
  558.             lblDwnPay.Caption = "Percent Down"
  559.         Case 1
  560.             mnuOptDwn(0).Checked = False
  561.             mnuOptDwn(1).Checked = True
  562.             lblDwnPay.Caption = "Amount Down"
  563.     End Select
  564. End Sub
  565. Sub mnuOptExit_Click ()
  566.     End
  567. End Sub
  568. Sub mnuOptInstruct_Click ()
  569.     ' Declare local variables
  570.     Dim MsgText
  571.     Dim PB
  572.     ' Initialize paragraph break variable
  573.     PB = Chr$(10) & Chr$(13) & Chr$(10) & Chr$(13)
  574.     ' Display message
  575.     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."
  576.     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."
  577.     MsgText = MsgText & PB & "Highlight cells in the grid and select Copy from the Options menu to copy data to the Clipboard."
  578.     MsgBox MsgText, 64, "LoanSheet Instructions"
  579. End Sub
  580. Sub mnuOptLen_Click (Index As Integer)
  581.     Select Case Index
  582.         ' Loan length = years
  583.         Case 0
  584.             mnuOptLen(0).Checked = True
  585.             mnuOptLen(1).Checked = False
  586.             frmLoanLen.Caption = "Years in Loan"
  587.         ' Loan length = months
  588.         Case 1
  589.             mnuOptLen(0).Checked = False
  590.             mnuOptLen(1).Checked = True
  591.             frmLoanLen.Caption = "Months in Loan"
  592.     End Select
  593. End Sub
  594. Function MonthPay (Interest, Months)
  595.     MonthPay = LoanAmt * (Interest / (1 - (1 / ((1 + Interest) ^ Months))))
  596. End Function
  597. Sub ShowAmort ()
  598.     ' Declare local variables
  599.     Dim Count
  600.     Dim Row2Fill
  601.     Dim Col2Fill
  602.     Dim GridHgt
  603.     Dim GridWid
  604.     Dim NL
  605.     Dim IntrTotl
  606.     ' Clear contents of grid
  607.     ClearGrid
  608.     ' Initialize line break variable
  609.     NL = Chr$(10) & Chr$(13)
  610.     ' Set # of non-fixed cols (4)
  611.     grdPayments.Cols = 5
  612.     ' Replace picture in 0, 0 cell with text
  613.     grdPayments.Row = 0
  614.     grdPayments.Col = 0
  615.     grdPayments.Picture = LoadPicture()
  616.     grdPayments.Text = NL & "Payment" & NL & Format$(AmortPmnt, "Currency")
  617.     grdPayments.ColWidth(0) = 1.1 * TextWidth(grdPayments.Text)
  618.     ' Set remaining col headings
  619.     grdPayments.Col = 1
  620.     grdPayments.Text = NL & "Principal Paid"
  621.     grdPayments.Col = 2
  622.     grdPayments.Text = NL & "Interest Paid"
  623.     grdPayments.Col = 3
  624.     grdPayments.Text = NL & "Principal Balance"
  625.     grdPayments.Col = 4
  626.     grdPayments.Text = NL & "Total Interest"
  627.     ' Display vert scroll bar
  628.     grdPayments.ScrollBars = 3
  629.     ' Initialize variables for non-fixed height/width of grid less fixed
  630.     ' rows/cols and grid border (30).
  631.     GridHgt = grdPayments.Height - grdPayments.RowHeight(0) - 30
  632.     GridWid = grdPayments.Width - grdPayments.ColWidth(0) - 30
  633.     ' Set # of non-fixed rows
  634.     If Months > 16 Then
  635.         grdPayments.Rows = Months + 1
  636.     Else
  637.         grdPayments.Rows = 16
  638.     End If
  639.     ' 1st col = current column
  640.     grdPayments.Col = 0
  641.     ' Set row heights to evenly display 16 rows in non-fixed height and
  642.     ' show payment # in 1st col
  643.     For Count = 1 To Months
  644.         grdPayments.RowHeight(Count) = GridHgt / 16
  645.         grdPayments.Row = Count
  646.         grdPayments.Text = Count
  647.     Next Count
  648.     ' Set col widths to evenly display 2 columns in non-fixed width
  649.     ' less width of vert scroll bar.
  650.     For Count = 1 To 4
  651.         grdPayments.ColWidth(Count) = (GridWid - 255) / 2
  652.     Next Count
  653.     ' Set initial interest total
  654.     IntrTotl = 0
  655.     ' Put values of non-fixed rows in grid
  656.     For Row2Fill = 1 To Months
  657.         ' For each month in repayment period
  658.         grdPayments.Row = Row2Fill
  659.         ' Display part of payment applied to principal in 1st non-fixed col
  660.         grdPayments.Col = 1
  661.         grdPayments.Text = Format$(AmortPmnt - AmortData(Row2Fill, 2), "Currency")
  662.         ' Display interest paid this payment in 2nd non-fixed col
  663.         grdPayments.Col = 2
  664.         grdPayments.Text = Format$(AmortData(Row2Fill, 2), "Currency")
  665.         ' Display balance remaining on principal in 3rd non-fixed col
  666.         grdPayments.Col = 3
  667.         grdPayments.Text = Format$(AmortData(Row2Fill, 1), "Currency")
  668.         ' Display total interest paid to date in last non-fixed col
  669.         grdPayments.Col = 4
  670.         IntrTotl = IntrTotl + AmortData(Row2Fill, 2)
  671.         grdPayments.Text = Format$(IntrTotl, "Currency")
  672.     Next Row2Fill
  673.     ' Disable Calculate Amortization button
  674.     cmdCalcAmort.Enabled = False
  675.     ' Enable amortization flag
  676.     AmortFlag = True
  677. End Sub
  678. Sub ShowPmnts ()
  679.     ' Declare local variables
  680.     Dim Row2Fill
  681.     Dim Col2Fill
  682.     Dim NL As String
  683.     Dim PeriodTxt As String
  684.     ' Clear grid contents
  685.     ClearGrid
  686.     ' Reset picture in cell 0, 0
  687.     grdPayments.Row = 0
  688.     grdPayments.Col = 0
  689.     grdPayments.Picture = imgGraphic.Picture
  690.     grdPayments.ColWidth(0) = imgGraphic.Width
  691.     ' Size non-fixed cells
  692.     SizeCells grdPayments
  693.     ' Initialize line break variable
  694.     NL = Chr$(10) & Chr$(13)
  695.     ' Initialize variable for loan period (years or months)
  696.     If mnuOptLen(0).Checked = True Then
  697.         PeriodTxt = "Years"
  698.     Else
  699.         PeriodTxt = "Months"
  700.     End If
  701.     ' 1st row = current row
  702.     grdPayments.Row = 0
  703.     ' Put col headings in 1st row
  704.     For Col2Fill = 1 To Periods
  705.         grdPayments.Col = Col2Fill
  706.         grdPayments.FixedAlignment(Col2Fill) = 2
  707.         grdPayments.Text = NL & Payments(0, Col2Fill) & NL & PeriodTxt
  708.     Next Col2Fill
  709.     ' Center text in 1st col
  710.     grdPayments.FixedAlignment(0) = 2
  711.     ' Put row headings in 1st col
  712.     grdPayments.Col = 0
  713.     For Row2Fill = 1 To Rates
  714.         grdPayments.Row = Row2Fill
  715.         grdPayments.Text = Format$(Payments(Row2Fill, 0), "0.0") & "%"
  716.     Next Row2Fill
  717.     ' Fill grid with payments from array
  718.     For Row2Fill = 1 To Rates
  719.         For Col2Fill = 1 To Periods
  720.             grdPayments.Row = Row2Fill
  721.             grdPayments.Col = Col2Fill
  722.             grdPayments.ColAlignment(Col2Fill) = 2
  723.             grdPayments.Text = Format$(Payments(Row2Fill, Col2Fill), "Currency")
  724.         Next Col2Fill
  725.     Next Row2Fill
  726.     ' Allow cell highlighting
  727.     grdPayments.HighLight = True
  728.     ' Enable copying from cells to clipboard
  729.     mnuOptCopy.Enabled = True
  730.     ' Set amortization flag to false
  731.     AmortFlag = False
  732. End Sub
  733. Sub SizeCells (ThisGrid As Control)
  734.     ' Declare local variables
  735.     Dim Count
  736.     Dim GridHgt
  737.     Dim GridWid
  738.     Dim ScrollHgt
  739.     Dim ScrollWid
  740.     ' Initialize variables for non-fixed height/width of grid less
  741.     ' fixed row/column and grid border (30)
  742.     GridHgt = ThisGrid.Height - ThisGrid.RowHeight(0) - 30
  743.     GridWid = ThisGrid.Width - ThisGrid.ColWidth(0) - 30
  744.     ' Initialize variables for scroll bar height/width
  745.     ScrollHgt = 255
  746.     ScrollWid = 255
  747.     ' If data fits in default # of rows (16) and cols (3)
  748.     If Rates <= 16 And Periods <= 3 Then
  749.         ' Don't display scroll bars
  750.         ThisGrid.ScrollBars = 0
  751.         ' Set # of non-fixed rows/cols to default
  752.         ThisGrid.Rows = 17
  753.         ThisGrid.Cols = 4
  754.         ' Set row heights to evenly display 16 rows in non-fixed grid height
  755.         For Count = 1 To 16
  756.             ThisGrid.RowHeight(Count) = GridHgt / 16
  757.         Next Count
  758.         ' Set col widths to evenly display 3 columns in non-fixed grid width.
  759.         For Count = 1 To 3
  760.             ThisGrid.ColWidth(Count) = GridWid / 3
  761.         Next Count
  762.     ' If data needs more columns, but rows are OK
  763.     ElseIf Rates <= 16 And Periods > 3 Then
  764.         ' Display horiz scroll bar only
  765.         ThisGrid.ScrollBars = 1
  766.         ' Set # of non-fixed rows and cols
  767.         ThisGrid.Rows = 17
  768.         ThisGrid.Cols = Periods + 1
  769.         ' Set row heights to evenly display 16 rows in non-fixed grid height
  770.         ' minus scroll bar height
  771.         For Count = 1 To 16
  772.             ThisGrid.RowHeight(Count) = (GridHgt - ScrollHgt) / 16
  773.         Next Count
  774.         ' Set column widths to evenly display 3 columns in non-fixed grid width.
  775.         For Count = 1 To Periods
  776.             ThisGrid.ColWidth(Count) = GridWid / 3
  777.         Next Count
  778.     ' If data needs more rows, but cols are OK
  779.     ElseIf Rates > 16 And Periods <= 3 Then
  780.         ' Display vert scroll bar only
  781.         ThisGrid.ScrollBars = 2
  782.         ' Set number of non-fixed rows and cols
  783.         ThisGrid.Rows = Rates + 1
  784.         ThisGrid.Cols = 4
  785.         ' Set row heights to evenly display 16 rows in non-fixed grid height.
  786.         For Count = 1 To Rates
  787.             ThisGrid.RowHeight(Count) = GridHgt / 16
  788.         Next Count
  789.         ' Set col widths to evenly display 3 columns in non-fixed grid width
  790.         ' minus scroll bar width
  791.         For Count = 1 To 3
  792.             ThisGrid.ColWidth(Count) = (GridWid - ScrollWid) / 3
  793.         Next Count
  794.     ElseIf Rates > 16 And Periods > 3 Then
  795.         ' Display both scroll bars
  796.         ThisGrid.ScrollBars = 3
  797.         ' Set number of non-fixed rows/cols
  798.         ThisGrid.Rows = Rates + 1
  799.         ThisGrid.Cols = Periods + 1
  800.         ' Set row heights to evenly display 16 rows in non-fixed grid height
  801.         ' minus scroll bar height
  802.         For Count = 1 To Rates
  803.             ThisGrid.RowHeight(Count) = (GridHgt - ScrollHgt) / 16
  804.         Next Count
  805.         ' Set column widths to evenly display 3 columns in non-fixed grid width
  806.         ' minus scroll bar width
  807.         For Count = 1 To Periods
  808.             ThisGrid.ColWidth(Count) = (GridWid - ScrollWid) / 3
  809.         Next Count
  810.     End If
  811. End Sub
  812. Sub txtDwnPay_Change ()
  813.     ' Store number into form variable
  814.     DPAmt = Val(txtDwnPay.Text)
  815.     ' Validate that DPAmt doesn't exceed 100% or Purchase Amount
  816.     If mnuOptDwn(0).Checked = True And DPAmt > 99 Then
  817.         MsgBox "Down payment percentage cannot exceed 99 percent.", 48, "LoanSheet Error"
  818.         txtDwnPay.Text = ""
  819.         txtDwnPay.SetFocus
  820.     ElseIf mnuOptDwn(1).Checked = True And DPAmt > PurchAmt Then
  821.         MsgBox "Down payment amount cannot exceed purchase amount.", 48, "LoanSheet Error"
  822.         txtDwnPay.Text = ""
  823.         txtDwnPay.SetFocus
  824.     ElseIf DPAmt < 0 Then
  825.         MsgBox "Down payment amount must be zero or greater.", 48, "LoanSheet Error"
  826.         txtDwnPay.Text = ""
  827.         txtDwnPay.SetFocus
  828.     End If
  829. End Sub
  830. Sub txtLenMax_Change ()
  831.     LenMax = Val(txtLenMax.Text)
  832. End Sub
  833. Sub txtLenMin_Change ()
  834.     LenMin = Val(txtLenMin.Text)
  835. End Sub
  836. Sub txtPurchTotl_Change ()
  837.     PurchAmt = Val(txtPurchTotl.Text)
  838. End Sub
  839.