home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l407 / 1.ddi / FILOPEN.BA_ / FILOPEN.bin
Encoding:
Text File  |  1993-04-28  |  2.6 KB  |  106 lines

  1.  
  2. Sub FOpenProc ()
  3.     Dim RetVal
  4.     On Error Resume Next
  5.     Dim OpenFileName As String
  6.     frmMDI.CMDialog1.Filename = ""
  7.     frmMDI.CMDialog1.Action = 1
  8.     If Err <> 32755 Then 'user pressed cancel
  9.     OpenFileName = frmMDI.CMDialog1.Filename
  10.     OpenFile (OpenFileName)
  11.     UpdateFileMenu (OpenFileName)
  12.     End If
  13. End Sub
  14.  
  15. Function GetFileName ()
  16.     'Displays a Save As dialog and returns a file name
  17.     'or an empty string if the user cancels
  18.     On Error Resume Next
  19.     frmMDI.CMDialog1.Filename = ""
  20.     frmMDI.CMDialog1.Action = 2
  21.     If Err <> 32755 Then      'User cancelled dialog
  22.     GetFileName = frmMDI.CMDialog1.Filename
  23.     Else
  24.     GetFileName = ""
  25.     End If
  26. End Function
  27.  
  28. Function OnRecentFilesList (FileName) As Integer
  29.   Dim i
  30.  
  31.   For i = 1 To 4
  32.     If frmMDI.mnuRecentFile(i).Caption = FileName Then
  33.       OnRecentFilesList = True
  34.       Exit Function
  35.     End If
  36.   Next i
  37.     OnRecentFilesList = False
  38. End Function
  39.  
  40. Sub OpenFile (FileName)
  41.     Dim NL, TextIn, GetLine
  42.     Dim fIndex As Integer
  43.  
  44.     NL = Chr$(13) + Chr$(10)
  45.     
  46.     On Error Resume Next
  47.     ' open the selected file
  48.     Open FileName For Input As #1
  49.     If Err Then
  50.     MsgBox "Can't open file: " + FileName
  51.     Exit Sub
  52.     End If
  53.     ' change mousepointer to an hourglass
  54.     screen.MousePointer = 11
  55.     
  56.     ' change form's caption and display new text
  57.     fIndex = FindFreeIndex()
  58.     document(fIndex).Tag = fIndex
  59.     document(fIndex).Caption = UCase$(FileName)
  60.     document(fIndex).Text1.Text = Input$(LOF(1), 1)
  61.     FState(fIndex).Dirty = False
  62.     document(fIndex).Show
  63.     Close #1
  64.     ' reset mouse pointer
  65.     screen.MousePointer = 0
  66. End Sub
  67.  
  68. Sub SaveFileAs (FileName)
  69. On Error Resume Next
  70.     Dim Contents As String
  71.  
  72.     ' open the file
  73.     Open FileName For Output As #1
  74.     ' put contents of the notepad into a variable
  75.     Contents = frmMDI.ActiveForm.Text1.Text
  76.     ' display hourglass
  77.     screen.MousePointer = 11
  78.     ' write variable contents to saved file
  79.     Print #1, Contents
  80.     Close #1
  81.     ' reset the mousepointer
  82.     screen.MousePointer = 0
  83.     ' set the Notepad's caption
  84.  
  85.     If Err Then
  86.     MsgBox Error, 48, App.Title
  87.     Else
  88.     frmMDI.ActiveForm.Caption = UCase$(FileName)
  89.     ' reset the dirty flag
  90.     FState(frmMDI.ActiveForm.Tag).Dirty = False
  91.     End If
  92. End Sub
  93.  
  94. Sub UpdateFileMenu (FileName)
  95.     Dim RetVal
  96.     ' Check if OpenFileName is already on MRU list.
  97.     RetVal = OnRecentFilesList(FileName)
  98.     If Not RetVal Then
  99.       ' Write OpenFileName to MDINOTEPAD.INI
  100.       WriteRecentFiles (FileName)
  101.     End If
  102.     ' Update menus for most recent file list.
  103.     GetRecentFiles
  104. End Sub
  105.  
  106.