home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l406 / 1.ddi / LOAN.FR_ / LOAN.bin (.txt)
Encoding:
Visual Basic Form  |  1992-10-21  |  27.9 KB  |  829 lines

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