home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / PGUIDE / SDI / FILOPEN.BAS next >
Encoding:
BASIC Source File  |  1996-09-16  |  3.5 KB  |  119 lines

  1. Attribute VB_Name = "Module2"
  2. '*** Standard module with procedures for working with   ***
  3. '*** files. Part of the SDI Notepad sample application. ***
  4. '**********************************************************
  5. Option Explicit
  6.  
  7. Sub FileOpenProc()
  8.     Dim intRetVal
  9.     Dim intResponse As Integer
  10.     Dim strOpenFileName As String
  11.     
  12.     ' If the file has changed, save it
  13.     If FState.Dirty = True Then
  14.         intResponse = FileSave
  15.         If intResponse = False Then Exit Sub
  16.     End If
  17.     On Error Resume Next
  18.     
  19.     frmSDI.CMDialog1.Filename = ""
  20.     frmSDI.CMDialog1.ShowOpen
  21.     If Err <> 32755 Then    ' User chose Cancel.
  22.         strOpenFileName = frmSDI.CMDialog1.Filename
  23.         ' If the file is larger than 65K, it can't
  24.         ' be opened, so cancel the operation.
  25.         If FileLen(strOpenFileName) > 65000 Then
  26.             MsgBox "The file is too large to open."
  27.             Exit Sub
  28.         End If
  29.         
  30.         OpenFile (strOpenFileName)
  31.         UpdateFileMenu (strOpenFileName)
  32.     End If
  33. End Sub
  34.  
  35. Function GetFileName(Filename As Variant)
  36.     ' Display a Save As dialog box and return a filename.
  37.     ' If the user chooses Cancel, return an empty string.
  38.     On Error Resume Next
  39.     frmSDI.CMDialog1.Filename = Filename
  40.     frmSDI.CMDialog1.ShowSave
  41.     If Err <> 32755 Then    ' User chose Cancel.
  42.         GetFileName = frmSDI.CMDialog1.Filename
  43.     Else
  44.         GetFileName = ""
  45.     End If
  46. End Function
  47.  
  48. Function OnRecentFilesList(Filename) As Integer
  49.     Dim i         ' Counter variable.
  50.  
  51.     For i = 1 To 4
  52.         If frmSDI.mnuRecentFile(i).Caption = Filename Then
  53.             OnRecentFilesList = True
  54.             Exit Function
  55.         End If
  56.     Next i
  57.     OnRecentFilesList = False
  58. End Function
  59.  
  60. Sub OpenFile(Filename)
  61.     Dim fIndex As Integer
  62.     
  63.     On Error Resume Next
  64.     ' Open the selected file.
  65.     Open Filename For Input As #1
  66.     If Err Then
  67.         MsgBox "Can't open file: " + Filename
  68.         Exit Sub
  69.     End If
  70.     ' Change the mouse pointer to an hourglass.
  71.     Screen.MousePointer = 11
  72.     
  73.     ' Change the form's caption and display the new text.
  74.     frmSDI.Caption = "SDI NotePad - " & UCase(Filename)
  75.     frmSDI.txtNote.Text = Input(LOF(1), 1)
  76.     FState.Dirty = False
  77.     Close #1
  78.     ' Reset the mouse pointer.
  79.     Screen.MousePointer = 0
  80. End Sub
  81.  
  82. Sub SaveFileAs(Filename)
  83.     On Error Resume Next
  84.     Dim strContents As String
  85.  
  86.     ' Open the file.
  87.     Open Filename For Output As #1
  88.     ' Place the contents of the notepad into a variable.
  89.     strContents = frmSDI.txtNote.Text
  90.     ' Display the hourglass mouse pointer.
  91.     Screen.MousePointer = 11
  92.     ' Write the variable contents to a saved file.
  93.     Print #1, strContents
  94.     Close #1
  95.     ' Reset the mouse pointer.
  96.     Screen.MousePointer = 0
  97.     ' Set the form's caption.
  98.     If Err Then
  99.         MsgBox Error, 48, App.Title
  100.     Else
  101.         frmSDI.Caption = "SDI NotePad - " & Filename
  102.         ' Reset the dirty flag.
  103.         FState.Dirty = False
  104.     End If
  105. End Sub
  106.  
  107. Sub UpdateFileMenu(Filename)
  108.         Dim intRetVal As Integer
  109.         ' Check if the open filename is already in the File menu control array.
  110.         intRetVal = OnRecentFilesList(Filename)
  111.         If Not intRetVal Then
  112.             ' Write open filename to the registry.
  113.             WriteRecentFiles (Filename)
  114.         End If
  115.         ' Update the list of the most recently opened files in the File menu control array.
  116.         GetRecentFiles
  117. End Sub
  118.  
  119.