home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 13 / CD_ASCQ_13_0494.iso / maj / 1697 / samples / filopen.bas < prev    next >
BASIC Source File  |  1993-11-21  |  3KB  |  109 lines

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