home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l406 / 4.ddi / SAVINGS.BA_ / SAVINGS.bin
Encoding:
Text File  |  1992-10-21  |  24.9 KB  |  691 lines

  1. 'Declare Global Constants used throughout the application
  2. Global Const intTotalforms = 30
  3. Global Col(intTotalforms) As frmCollege
  4. Global Gen(intTotalforms) As frmGeneral
  5. Global ComGrid(intTotalforms) As frmGrid
  6. Global GenGraph(intTotalforms) As frmGraph
  7. Global ColForm As Integer
  8. Global GenForm As Integer
  9. Global GriForm As Integer
  10. Global GraForm As Integer
  11. Global TotalColCost As Variant
  12. Global TotalDiscColCost As Variant
  13. Global FormNo As Variant
  14. Global NeedToSave As Variant
  15. Global GoalType As String
  16. Global FormNumb As Variant
  17. Global AmtToSaveArray(100) As Variant
  18. Global CumAmtSavedArray(100) As Variant
  19. Global IntAmtArray(100) As Variant
  20. Global CumIntArray(100) As Variant
  21. Global SelectCancel As Integer
  22.  
  23. ' Arrange Method for MDI Forms
  24. Global Const CASCADE = 0
  25. Global Const ARRANGE_ICONS = 3
  26.  
  27. ' Show parameters
  28. Global Const MODAL = 1
  29. Global Const MODELESS = 0
  30.  
  31. ' Help engine declarations.
  32. Declare Function WinHelp Lib "User" (ByVal hWnd As Integer, ByVal lpHelpFile As String, ByVal wCommand As Integer, dwData As Any) As Integer
  33.  
  34. ' Commands to pass WinHelp()
  35. Global Const HELP_CONTEXT = &H1     ' Display topic identified by number in Data
  36. Global Const HELP_QUIT = &H2        ' Terminate help
  37. Global Const HELP_INDEX = &H3       ' Display index
  38. Global Const HELP_HELPONHELP = &H4  ' Display help on using help
  39. Global Const HELP_SETINDEX = &H5    ' Set an alternate Index for help file with more than one index
  40. Global Const HELP_KEY = &H101       ' Display topic for keyword in Data
  41. Global Const HELP_MULTIKEY = &H201  ' Lookup keyword in alternate table and display topic
  42.  
  43.  
  44. ' Memory management functions for determining system information
  45. ' displayed in the About Dialog
  46.  
  47. ' Returns the current system configurations flags
  48. Declare Function GetWinFlags Lib "kernel" () As Long
  49.  
  50. ' Returns the number of free bytes in the global heap
  51. Declare Function GetFreeSpace Lib "kernel" (ByVal flag%) As Long
  52.  
  53. ' System configuration flags
  54. Global Const WF_CPU286 = &H2&
  55. Global Const WF_CPU386 = &H4&
  56. Global Const WF_CPU486 = &H8&
  57. Global Const WF_STANDARD = &H10&
  58. Global Const WF_ENHANCED = &H20&
  59. Global Const WF_80x87 = &H400&
  60.  
  61.  
  62. Sub ButtonsHide ()
  63.     ' Hide the graph and grid buttons on the toolbar
  64.     If frmMDI.Line25.Visible = True Then
  65.         frmMDI.Line25.Visible = False
  66.         frmMDI.Line26.Visible = False
  67.         frmMDI.Line27.Visible = False
  68.         frmMDI.Line28.Visible = False
  69.         frmMDI.Line29.Visible = False
  70.         frmMDI.Line30.Visible = False
  71.         frmMDI.Line31.Visible = False
  72.         frmMDI.Line32.Visible = False
  73.         frmMDI.Line33.Visible = False
  74.         frmMDI.Line34.Visible = False
  75.         frmMDI.Line35.Visible = False
  76.         frmMDI.Line36.Visible = False
  77.         frmMDI.Line37.Visible = False
  78.         frmMDI.Line38.Visible = False
  79.         frmMDI.Line39.Visible = False
  80.         frmMDI.Line40.Visible = False
  81.         frmMDI.imgGraph.Visible = False
  82.         frmMDI.imgComGraph.Visible = False
  83.         frmMDI.imgGrid.Visible = False
  84.         frmMDI.imgComGrid.Visible = False
  85.         frmMDI.Shape6.Visible = False
  86.         frmMDI.Shape7.Visible = False
  87.         frmMDI.Shape8.Visible = False
  88.         frmMDI.Shape9.Visible = False
  89.     End If
  90. End Sub
  91.  
  92. Sub ButtonsVisible ()
  93.     ' Make the graph and grid buttons visible on the toolbar
  94.     If frmMDI.Line25.Visible = False Then
  95.         frmMDI.Line25.Visible = True
  96.         frmMDI.Line26.Visible = True
  97.         frmMDI.Line27.Visible = True
  98.         frmMDI.Line28.Visible = True
  99.         frmMDI.Line29.Visible = True
  100.         frmMDI.Line30.Visible = True
  101.         frmMDI.Line31.Visible = True
  102.         frmMDI.Line32.Visible = True
  103.         frmMDI.Line33.Visible = True
  104.         frmMDI.Line34.Visible = True
  105.         frmMDI.Line35.Visible = True
  106.         frmMDI.Line36.Visible = True
  107.         frmMDI.Line37.Visible = True
  108.         frmMDI.Line38.Visible = True
  109.         frmMDI.Line39.Visible = True
  110.         frmMDI.Line40.Visible = True
  111.         frmMDI.imgGraph.Visible = True
  112.         frmMDI.imgComGraph.Visible = True
  113.         frmMDI.imgGrid.Visible = True
  114.         frmMDI.imgComGrid.Visible = True
  115.         frmMDI.Shape6.Visible = True
  116.         frmMDI.Shape7.Visible = True
  117.         frmMDI.Shape8.Visible = True
  118.         frmMDI.Shape9.Visible = True
  119.     End If
  120. End Sub
  121.  
  122. Sub CenterForm (frmParent As MDIForm, frmChild As Form)
  123. ' This procedure centers a child form over a parent form.
  124. ' Calling this routine loads the dialog. Use the Show method
  125. ' to display the dialog after calling this routine ( ie MyFrm.Show 1)
  126.  
  127.   ' get left offset
  128.   l = frmParent.Left + ((frmParent.Width - frmChild.Width) / 2)
  129.   If (l + frmChild.Width > Screen.Width) Then
  130.     l = Screen.Width = frmChild.Width
  131.   End If
  132.  
  133.   ' get top offset
  134.   t = frmParent.Top + ((frmParent.Height - frmChild.Height) / 2)
  135.   If (t + frmChild.Height > Screen.Height) Then
  136.     t = Screen.Height - frmChild.Height
  137.   End If
  138.  
  139.   ' center the child formfv
  140.   frmChild.Move l, t
  141.  
  142. End Sub
  143.  
  144. Sub CheckToSave ()
  145.     ' This routine is run if changes are made and you are quitting,
  146.     ' loading another plan, or starting a new plan
  147.     SelectCancel = False
  148.     AskCheck = False
  149.     For i = 0 To forms.Count - 1
  150.         If forms(i).Tag = "College" Or forms(i).Tag = "General" Then
  151.             AskCheck = True
  152.         End If
  153.     Next
  154.     If AskCheck Then
  155.         Dim Msg, NL
  156.         Dim Response As Integer
  157.         NL = Chr$(10) & Chr$(13)
  158.         Msg = "The information in this savings plan has been changed."
  159.         Msg = Msg & NL
  160.         Msg = Msg & "Do you want to save the changes?"
  161.         Response = MsgBox(Msg, 51)
  162.         Select Case Response
  163.         Case 2  'User selects Cancel, cancel the unload
  164.             SelectCancel = True
  165.             Cancel = True
  166.         Case 6  'User select Yes, save the savings plan
  167.             SelectCancel = False
  168.             SavePlan    'Invoke the Save procedure
  169.         Case 7  'User selects No, Ok to unload
  170.             SelectCancel = False
  171.             Cancel = False
  172.         End Select
  173.     End If
  174. End Sub
  175.  
  176. Function colpmt (c, ci, IntRate, n, ny, S, PerType)
  177. On Error GoTo FixColPmtError
  178.     ' This routine calculates the amount to save for college
  179.     ' c=Current College annual expense
  180.     ' ci=Annual percent increase in College expense
  181.     ' intrate=rate of return expected on investments
  182.     ' n=number of years till college
  183.     ' ny=number of years in college
  184.     ' s=amount already saved toward college
  185.     ' PerType = Yearly (1) or Monthly (2)
  186.     TotalColCost = 0: TotalDiscColCost = 0
  187.     For i = 0 To ny - 1
  188.         ColCost = c * (1 + ci) ^ (n + i)'Cost at that year
  189.         TotalColCost = TotalColCost + ColCost
  190.         DiscColCost = ColCost * (1 + IntRate) ^ -(n + i) 'Present Value of that year
  191.         TotalDiscColCost = TotalDiscColCost + DiscColCost
  192.     Next i
  193.     If PerType <> 1 Then
  194.         IntRate = IntRate / 12: n = n * 12 - 11: ny = ny * 12
  195.     End If
  196.     colpmt = (TotalDiscColCost - S) * (IntRate / (1 - (1 + IntRate) ^ -(n + ny - 1)))
  197.     Exit Function
  198.  
  199. FixColPmtError:
  200.     If Err Then
  201.         MsgBox Error$
  202.         Exit Function
  203.     End If
  204. End Function
  205.  
  206. Sub FOpenProc ()
  207.     'Open form to open a savings plan
  208.     frmForm.Caption = "Open"
  209.     CenterForm frmMDI, frmForm
  210.     frmForm.Show MODAL
  211. End Sub
  212.  
  213. Sub FormSelectProc (ButtonType As String)
  214.     ' Select which forms are to be graphed or gridded using combined method
  215.     ' Set the form's caption
  216.     If ButtonType = "Graph" Then
  217.         frmFormSelect.Caption = "Graph which goals?"
  218.         frmFormSelect.cmdGo.Caption = "Graph"
  219.     ElseIf ButtonType = "Grid" Then
  220.         frmFormSelect.cmdGo.Caption = "Grid"
  221.         frmFormSelect.Caption = "Grid which goals?"
  222.     End If
  223.     ' Center the FileOpen/Save form over the MDI form
  224.     CenterForm frmMDI, frmFormSelect
  225.     ' Show the FileOpen/Save form
  226.     On Error Resume Next
  227.     Err = 0: j = 0: ReDim FormSelFormNumb(10) As Integer: ReDim FormSelGoalType(10) As String
  228.     For i = 0 To forms.Count - 1
  229.         If forms(i).Tag = "College" Or forms(i).Tag = "General" Then
  230.             frmFormSelect.lstFormSelect.AddItem forms(i).Caption
  231.         End If
  232.     Next
  233.     frmFormSelect.Show MODAL
  234. End Sub
  235.  
  236. Sub GraphIt (TagStr As String, GName, GIntRate, GPer, GSaved, AmtToSave, GGoal, GCAge, GAge, Divider, GCAnnCost, GColInc, GType)
  237. On Error GoTo FixGraphIt
  238.     'Routine to graph single goal
  239.     'Tagstr = is the value of the Tag property of the goal form
  240.     'GName = is the Goal Name
  241.     'GIntRate = Rate of Return of investment per period
  242.     'GPer = number of periods
  243.     'GSaved = Amount already saved
  244.     'AmtToSave = Amount to save per period
  245.     'GGoal = Total goal to be saved
  246.     'GCAge = Age at beginning of College
  247.     'GAge = Current age
  248.     'Divider = how much to divide the interest rate by for 8%=0.08
  249.     'GCAnnCost= Current annual cost of college
  250.     'GColInc = Annual Cost of College
  251.     'GType = 1 for General, 2 for College goal
  252.     'display hourglass for pointer
  253.     Screen.MousePointer = 11
  254.     
  255.     FormNo = Val(Mid$(TagStr, 8))
  256.     
  257.     'Open new instance of frmGraph
  258.     Set GenGraph(FormNo) = New frmGraph
  259.     GenGraph(FormNo).Caption = GName + " - Graph"
  260.     
  261.     'Determine maximum scale amount
  262.     intMaxScale = (Int((GGoal - 1) / 1000) + 1) * 1000
  263.     
  264.     'Place the year labels on the form
  265.     For i = 0 To GPer - 1
  266.         If i <> 0 Then
  267.             Load GenGraph(FormNo).lblPerNo(i)
  268.             GenGraph(FormNo).lblPerNo(i).Left = GenGraph(FormNo).lblPerNo(i - 1).Left + GenGraph(FormNo).lblPerNo(i - 1).Width
  269.         End If
  270.         GenGraph(FormNo).lblPerNo(i).Width = 7000 / GPer
  271.         GenGraph(FormNo).lblPerNo(i).Caption = i + 1
  272.         GenGraph(FormNo).lblPerNo(i).Enabled = True
  273.         GenGraph(FormNo).lblPerNo(i).Visible = True
  274.     Next i
  275.  
  276.     'Place the dollar amount labels on the form
  277.     For i = 0 To 9
  278.         If i <> 0 Then
  279.             Load GenGraph(FormNo).Line3(i)
  280.             Load GenGraph(FormNo).Label1(i)
  281.             GenGraph(FormNo).Line3(i).Y1 = GenGraph(FormNo).Line3(i - 1).Y1 - 400
  282.             GenGraph(FormNo).Line3(i).Y2 = GenGraph(FormNo).Line3(i - 1).Y1 - 400
  283.             GenGraph(FormNo).Label1(i).Top = GenGraph(FormNo).Label1(i - 1).Top - 400
  284.         End If
  285.         GenGraph(FormNo).Line3(i).Visible = True
  286.         GenGraph(FormNo).Label1(i).Caption = Format$(intMaxScale / 10 * (i + 1), "$###,###")
  287.         GenGraph(FormNo).Label1(i).Enabled = True
  288.         GenGraph(FormNo).Label1(i).Visible = True
  289.     Next
  290.     
  291.     'Place the principal and interest bars on form
  292.     CumInt = 0: IntAmt = 0: CumAmtSaved = GSaved: CumTotal = GSaved
  293.     For i = 0 To (GPer - 1) * 2 Step 2
  294.         
  295.         'New GraphBox for cumulative amount saved
  296.         If i <> 0 Then Load GenGraph(FormNo).GraphBox(i)
  297.         
  298.         CumAmtSaved = CumAmtSaved + AmtToSave
  299.         IntAmt = CumTotal * GIntRate
  300.         CumInt = CumInt + IntAmt
  301.         If (CumAmtSaved * 4000 / GGoal) < 1 Then
  302.             GenGraph(FormNo).GraphBox(i).Height = 1
  303.         Else
  304.             GenGraph(FormNo).GraphBox(i).Height = CumAmtSaved * 4000 / GGoal
  305.         End If
  306.         GenGraph(FormNo).GraphBox(i).Top = 4440 - GenGraph(FormNo).GraphBox(i).Height
  307.         GenGraph(FormNo).GraphBox(i).Width = 7000 / GPer - 30
  308.         If i <> 0 Then GenGraph(FormNo).GraphBox(i).Left = GenGraph(FormNo).GraphBox(i - 2).Left + GenGraph(FormNo).GraphBox(i).Width + 30
  309.         GenGraph(FormNo).GraphBox(i).Visible = True
  310.         If CumInt * 4000 / GGoal >= 1 Then
  311.             
  312.             'New GraphBox for cumulative interest
  313.             Load GenGraph(FormNo).GraphBox(i + 1)
  314.             GenGraph(FormNo).GraphBox(i + 1).Height = CumInt * 4000 / GGoal
  315.             
  316.             GenGraph(FormNo).GraphBox(i + 1).Top = GenGraph(FormNo).GraphBox(i).Top - GenGraph(FormNo).GraphBox(i + 1).Height
  317.             GenGraph(FormNo).GraphBox(i + 1).Width = 7000 / GPer - 30
  318.             GenGraph(FormNo).GraphBox(i + 1).Left = GenGraph(FormNo).GraphBox(i).Left
  319.             GenGraph(FormNo).GraphBox(i + 1).BackColor = QBColor(14)
  320.             GenGraph(FormNo).GraphBox(i + 1).Visible = True
  321.         End If
  322.         CumTotal = CumTotal + AmtToSave + IntAmt
  323.         
  324.         ' Check for start of each year of College and
  325.         ' subtract out cost of College
  326.         If i >= (Val(GCAge) - Val(GAge)) * 2 - 2 And GType = 2 Then
  327.             CumTotal = CumTotal - GCAnnCost * (1 + GColInc / 100) ^ ((i + 2) / 2)
  328.         End If
  329.  
  330.         If i = GPer - 1 And GType = 1 Then
  331.             CumTotal = CumTotal - GPrice
  332.         End If
  333.     Next i
  334.     
  335.     'Update status bar
  336.     GenGraph(FormNo).lblCumAmtSaved = Format$(CumAmtSaved, " $##,###,###,###")
  337.     GenGraph(FormNo).lblCumInt = Format$(CumInt, " $##,###,###,###")
  338.     If TagStr = "College" Then
  339.         CumTotal = CumInt + CumAmtSaved
  340.     End If
  341.     GenGraph(FormNo).lblCumTotal = Format$(CumTotal, " $###,###,###,###")
  342.     
  343.     GenGraph(FormNo).Show
  344.     
  345.     'Change mouse pointer back to point
  346.     Screen.MousePointer = 0
  347.     Exit Sub
  348.  
  349. FixGraphIt:
  350.     If Err Then
  351.         MsgBox Error$
  352.         Screen.MousePointer = 0
  353.         Exit Sub
  354.     End If
  355. End Sub
  356.  
  357. Sub GridSetup (GType, GName, GPeriods, GPrice, GiRate, GSaved, GCAge, GAge, GCYears, GCAnnCost, GColInc)
  358. On Error GoTo FixGridSetup:
  359.     'Routine to grid a single goal
  360.     
  361.     'set status bar values back to zero
  362.     CumGrAmtSaved = 0
  363.     CumGrIntAmt = 0
  364.     CumGrTotal = 0
  365.     
  366.     'display hourglass for pointer
  367.     Screen.MousePointer = 11
  368.     
  369.     'Open new instance of frmGrid form
  370.     Set ComGrid(GriForm) = New frmGrid
  371.     ComGrid(GriForm).Tag = GriForm
  372.     
  373.     ComGrid(GriForm).Caption = GName + " - Grid"
  374.  
  375.     'Set up the grids rows and columns
  376.     If GPeriods > 0 Then
  377.         ComGrid(GriForm).Grid1.Rows = GPeriods + 1
  378.     Else
  379.         ComGrid(GriForm).Grid1.Rows = 2
  380.     End If
  381.     ComGrid(GriForm).Grid1.Cols = 6: ComGrid(GriForm).Grid1.FixedCols = 0
  382.     ComGrid(GriForm).Grid1.ColWidth(0) = 600
  383.     ComGrid(GriForm).Grid1.RowHeight(0) = 700
  384.     ComGrid(GriForm).Grid1.ColAlignment(1) = 2
  385.     For i = 1 To 5
  386.         ComGrid(GriForm).Grid1.ColWidth(i) = 1350
  387.         ComGrid(GriForm).Grid1.ColAlignment(i) = 1
  388.     Next i
  389.     ComGrid(GriForm).Grid1.Row = 0: ComGrid(GriForm).Grid1.Col = 0: ComGrid(GriForm).Grid1.Text = "Years"
  390.     ComGrid(GriForm).Grid1.Col = 1: ComGrid(GriForm).Grid1.Text = "Amount Saved This Period"
  391.     ComGrid(GriForm).Grid1.Col = 2: ComGrid(GriForm).Grid1.Text = "Accumulated Amount Saved"
  392.     ComGrid(GriForm).Grid1.Col = 3: ComGrid(GriForm).Grid1.Text = "Interest Earned"
  393.     ComGrid(GriForm).Grid1.Col = 4: ComGrid(GriForm).Grid1.Text = "Accumulated Interest"
  394.     ComGrid(GriForm).Grid1.Col = 5: ComGrid(GriForm).Grid1.Text = "Total Accumulated Savings"
  395.     
  396.     'Determine the amount to save each year
  397.     If GType = 2 Then
  398.         AmtToSave = colpmt(GCAnnCost, GColInc / 100, GiRate / 100, GCAge - GAge, GCYears, GSaved, 1)
  399.     Else
  400.         AmtToSave = pmt(GPrice, GiRate / 100, GPeriods, GSaved)
  401.     End If
  402.     
  403.     'Fill in the grid
  404.     CumInt = 0: IntAmt = 0: CumAmtSaved = 0
  405.     CumAmtSaved = GSaved: CumTotal = GSaved: CumGrAmtSaved = GSaved
  406.     For i = 1 To GPeriods
  407.         ComGrid(GriForm).Grid1.Row = i
  408.         ComGrid(GriForm).Grid1.Col = 0: ComGrid(GriForm).Grid1.Text = Str$(i)
  409.         ComGrid(GriForm).Grid1.Col = 1: ComGrid(GriForm).Grid1.Text = Format$(AmtToSave, "$###,##0.00")
  410.         ComGrid(GriForm).Grid1.Col = 2: CumAmtSaved = CumAmtSaved + AmtToSave: ComGrid(GriForm).Grid1.Text = Format$(CumAmtSaved, "$###,##0.00")
  411.         ComGrid(GriForm).Grid1.Col = 3: IntAmt = (CumTotal) * GiRate / 100: ComGrid(GriForm).Grid1.Text = Format$(IntAmt, "$###,##0.00")
  412.         ComGrid(GriForm).Grid1.Col = 4: CumInt = CumInt + IntAmt: ComGrid(GriForm).Grid1.Text = Format$(CumInt, "$###,##0.00")
  413.         ' Check for start of each year of College
  414.         If i >= (Val(GCAge) - Val(GAge)) And i - Int(i) = 0 And GType = 2 Then
  415.             CumTotal = CumTotal - GCAnnCost * (1 + GColInc / 100) ^ (i)
  416.         End If
  417.         If i = GPeriods And GType = 1 Then
  418.             CumTotal = CumTotal - GPrice
  419.         End If
  420.         CumTotal = CumTotal + AmtToSave + IntAmt
  421.         ComGrid(GriForm).Grid1.Col = 5: ComGrid(GriForm).Grid1.Text = Format$(CumAmtSaved + CumInt, "$###,##0.00")
  422.         
  423.         'Save cumulative amounts for status bar
  424.         CumGrAmtSaved = CumGrAmtSaved + AmtToSave
  425.         CumGrIntAmt = CumGrIntAmt + IntAmt
  426.         CumGrTotal = CumGrAmtSaved + CumGrIntAmt
  427.     Next i
  428.     
  429.     'Place currency on the first row and column
  430.     ComGrid(GriForm).Grid1.Col = 1
  431.     ComGrid(GriForm).Grid1.Row = 1
  432.     
  433.     'Update the status bar
  434.     ComGrid(GriForm).lblCumTotal = Format$(CumGrTotal, " $###,###,###")
  435.     ComGrid(GriForm).lblCumAmtSaved = Format$(CumGrAmtSaved, " $###,###,###")
  436.     ComGrid(GriForm).lblCumInt = Format$(CumGrIntAmt, " $###,###,###")
  437.     
  438.     ComGrid(GriForm).Show
  439.     
  440.     'Change mouse pointer back to point
  441.     Screen.MousePointer = 0
  442.     Exit Sub
  443. FixGridSetup:
  444.     If Err Then
  445.         MsgBox Error$
  446.         Screen.MousePointer = 0
  447.         Exit Sub
  448.     End If
  449. End Sub
  450.  
  451. Sub NewCGoal ()
  452. On Error GoTo FixCGoalError
  453.     'Open a new instance of the college form
  454.     If ColForm <= intTotalforms Then
  455.         Set Col(ColForm) = New frmCollege
  456.         Col(ColForm).Show
  457.     End If
  458.     Exit Sub
  459. FixCGoalError:
  460.         If Err Then
  461.             MsgBox Error$
  462.             Exit Sub
  463.         End If
  464.     
  465. End Sub
  466.  
  467. Sub NewGGoal ()
  468. On Error GoTo FixGGoalError:
  469.     'Open a new instance of the general form
  470.     If GenForm <= intTotalforms Then
  471.         Set Gen(GenForm) = New frmGeneral
  472.         Gen(GenForm).Show
  473.     End If
  474.     Exit Sub
  475.  
  476. FixGGoalError:
  477.         If Err Then
  478.             MsgBox Error$
  479.             Exit Sub
  480.         End If
  481. End Sub
  482.  
  483. Sub NewSavePlan ()
  484.     Screen.MousePointer = 11
  485.     ' Since MDI forms don't have an MDIChild property,
  486.     ' the If statement below will cause an error when
  487.     ' the MDI form is evaluated.
  488.     On Error Resume Next
  489.     Err = 0
  490.     ' Iterate through all the goal forms
  491.     For i = 1 To forms.Count - 1
  492.         ' find all forms that have MDIChild = True
  493.         x = forms(1).MDIChild
  494.         If x Then
  495.             Unload forms(1)
  496.         End If
  497.     Next
  498.     NeedToSave = False
  499.     ' reset the mousepointer
  500.     Screen.MousePointer = 0
  501.     ' set the MDIForm's caption
  502.     frmMDI.Caption = "Savings - Untitled"
  503.     ColForm = 0: GenForm = 0: GriForm = 0: GraForm = 0
  504. End Sub
  505.  
  506. Sub OpenFile (FileName)
  507. On Error Resume Next
  508.     ' open the selected file
  509.     Open FileName For Input As #1
  510.     If Err Then
  511.         MsgBox Error$
  512.         Exit Sub
  513.     End If
  514.     ' change mousepointer to an hourglass
  515.     Screen.MousePointer = 11
  516.     
  517.     ' copy the file's contents into a variable
  518.     ColForm = 0: GenForm = 0
  519.     Do Until EOF(1)
  520.         Line Input #1, GetLine
  521.         TypeOfLine = Mid$(GetLine, 1, InStr(1, GetLine, ",") - 1)
  522.         GetLine = Mid$(GetLine, InStr(1, GetLine, ",") + 1, Len(GetLine))
  523.         If TypeOfLine = "College" Then
  524.             Set Col(ColForm) = New frmCollege
  525.             FormNo = ColForm
  526.             Col(FormNo).txtColName.Text = Mid$(GetLine, 1, InStr(1, GetLine, ",") - 1)
  527.             GetLine = Mid$(GetLine, InStr(1, GetLine, ",") + 1, Len(GetLine))
  528.             Col(FormNo).txtAge.Text = Mid$(GetLine, 1, InStr(1, GetLine, ",") - 1)
  529.             GetLine = Mid$(GetLine, InStr(1, GetLine, ",") + 1, Len(GetLine))
  530.             Col(FormNo).txtColAge = Mid$(GetLine, 1, InStr(1, GetLine, ",") - 1)
  531.             GetLine = Mid$(GetLine, InStr(1, GetLine, ",") + 1, Len(GetLine))
  532.             Col(FormNo).txtColAnnCost = Mid$(GetLine, 1, InStr(1, GetLine, ",") - 1)
  533.             GetLine = Mid$(GetLine, InStr(1, GetLine, ",") + 1, Len(GetLine))
  534.             Col(FormNo).txtColIncrease = Mid$(GetLine, 1, InStr(1, GetLine, ",") - 1)
  535.             GetLine = Mid$(GetLine, InStr(1, GetLine, ",") + 1, Len(GetLine))
  536.             Col(FormNo).txtColIntRate = Mid$(GetLine, 1, InStr(1, GetLine, ",") - 1)
  537.             GetLine = Mid$(GetLine, InStr(1, GetLine, ",") + 1, Len(GetLine))
  538.             Col(FormNo).txtColSaved = Mid$(GetLine, 1, InStr(1, GetLine, ",") - 1)
  539.             GetLine = Mid$(GetLine, InStr(1, GetLine, ",") + 1, Len(GetLine))
  540.             Col(FormNo).txtColYears = GetLine
  541.             Col(FormNo).Show
  542.         ElseIf TypeOfLine = "General" Then
  543.             Set Gen(GenForm) = New frmGeneral
  544.             FormNo = GenForm
  545.             Gen(FormNo).txtGenName = Mid$(GetLine, 1, InStr(1, GetLine, ",") - 1)
  546.             GetLine = Mid$(GetLine, InStr(1, GetLine, ",") + 1, Len(GetLine))
  547.             Gen(FormNo).txtGenPer = Mid$(GetLine, 1, InStr(1, GetLine, ",") - 1)
  548.             GetLine = Mid$(GetLine, InStr(1, GetLine, ",") + 1, Len(GetLine))
  549.             Gen(FormNo).txtGenIntRate = Mid$(GetLine, 1, InStr(1, GetLine, ",") - 1)
  550.             GetLine = Mid$(GetLine, InStr(1, GetLine, ",") + 1, Len(GetLine))
  551.             Gen(FormNo).txtGenPrice = Mid$(GetLine, 1, InStr(1, GetLine, ",") - 1)
  552.             GetLine = Mid$(GetLine, InStr(1, GetLine, ",") + 1, Len(GetLine))
  553.             Gen(FormNo).txtGenSaved = GetLine
  554.             Gen(FormNo).Show
  555.         Else
  556.             Screen.MousePointer = 0
  557.             MsgBox "Incorrect file format"
  558.             Close #1
  559.             Exit Sub
  560.         End If
  561.         TextIn = TextIn + GetLine + NL
  562.     Loop
  563.     Close #1
  564.         
  565.     ' change form's caption and display new text
  566.     frmMDI.Caption = "Savings - " + UCase$(FileName)
  567.     
  568.     ' unload the Open dialog
  569.     Unload frmForm
  570.     
  571.     ' reset mouse pointer
  572.     Screen.MousePointer = 0
  573.     NeedToSave = False
  574. End Sub
  575.  
  576. Sub OptionsToolbarProc (FormName As Form)
  577.     'Toggle the toolbar on and off
  578.     FormName.mnuToolbar.Checked = Not FormName.mnuToolbar.Checked
  579.     If FormName.mnuToolbar.Checked Then
  580.         frmMDI.picToolbar.Visible = True
  581.     Else
  582.         frmMDI.picToolbar.Visible = False
  583.     End If
  584. End Sub
  585.  
  586. Function pmt (P, i, n, S)
  587. On Error GoTo FixpmtError:
  588.     ' Returns the payment amount on a general goal
  589.     ' p=amount to accumlate with interest
  590.     ' i=expected rate of return on investment per period
  591.     ' n=number of periods
  592.     ' s=amount already saved toward goal
  593.     pmt = (P - S * (1 + i) ^ n) * i / ((1 + i) ^ n - 1)
  594.     Exit Function
  595. FixpmtError:
  596.     If Err Then
  597.         MsgBox Error$
  598.         Exit Function
  599.     End If
  600.  
  601. End Function
  602.  
  603. Sub SaveAsPlan ()
  604.     ' Set the form's caption
  605.     frmForm.Caption = "Save As"
  606.     ' Center the FileOpen/Save form over the MDI form
  607.     CenterForm frmMDI, frmForm
  608.     ' Show the FileOpen/Save form
  609.     frmForm.Show MODAL
  610. End Sub
  611.  
  612. Sub SaveFileAs (FileName)
  613.     On Error Resume Next
  614.  
  615.     If InStr(FileName, ".") = 0 Then
  616.         FileName = FileName + ".sav"
  617.     End If
  618.  
  619.     ' check if user wants to overwrite existing file
  620.     If Mid$(frmMDI.Caption, 11) <> UCase$(FileName) Then
  621.         If Dir(FileName) = UCase$(FileName) Then
  622.             n = MsgBox("Overwrite contents of file '" + FileName + "' ?", 36)
  623.             If n = 7 Then
  624.                 Exit Sub
  625.             End If
  626.         End If
  627.     End If
  628.  
  629.     ' open the file
  630.     Open FileName For Output As #1
  631.     
  632.     If Err Then
  633.        MsgBox Error$
  634.        Exit Sub
  635.     End If
  636.  
  637.     ' display hourglass
  638.     Screen.MousePointer = 11
  639.     ' Since MDI forms don't have an MDIChild property,
  640.     ' the If statement below will cause an error when
  641.     ' the MDI form is evaluated.
  642.    
  643.     Err = 0
  644.     ' Iterate through all the goal forms
  645.     For i = 0 To forms.Count - 1
  646.         ' find all forms that have MDIChild = True
  647.         x = forms(i).MDIChild
  648.         If x Then
  649.             If Mid$(forms(i).Tag, 1, 3) = "Col" Then
  650.                 Print #1, "College,";
  651.                 Print #1, forms(i).txtColName + ",";
  652.                 Print #1, forms(i).txtAge + ",";
  653.                 Print #1, forms(i).txtColAge + ",";
  654.                 Print #1, forms(i).txtColAnnCost + ",";
  655.                 Print #1, forms(i).txtColIncrease + ",";
  656.                 Print #1, forms(i).txtColIntRate + ",";
  657.                 Print #1, forms(i).txtColSaved + ",";
  658.                 Print #1, forms(i).txtColYears
  659.             ElseIf Mid$(forms(i).Tag, 1, 3) = "Gen" Then
  660.                 Print #1, "General,";
  661.                 Print #1, forms(i).txtGenName + ",";
  662.                 Print #1, forms(i).txtGenPer + ",";
  663.                 Print #1, forms(i).txtGenIntRate + ",";
  664.                 Print #1, forms(i).txtGenPrice + ",";
  665.                 Print #1, forms(i).txtGenSaved
  666.             End If
  667.         End If
  668.     Next i
  669.     Close #1
  670.     ' close the Save As dialog
  671.     Unload frmForm
  672.     ' reset the mousepointer
  673.     Screen.MousePointer = 0
  674.     ' set the MDIForm's caption
  675.     frmMDI.Caption = "Savings - " + UCase$(FileName)
  676.     NeedToSave = False
  677. End Sub
  678.  
  679. Sub SavePlan ()
  680.     If frmMDI.Caption = "Savings - Untitled" Then
  681.         ' The file hasn't been saved yet, call the
  682.         ' Save File As procedure which prompts for a file name
  683.         SaveAsPlan
  684.     Else
  685.         ' The caption contains the name of the open file
  686.         FileName = Mid$(frmMDI.Caption, 11)
  687.         SaveFileAs FileName
  688.     End If
  689. End Sub
  690.  
  691.