home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l406 / 1.ddi / TEXTEDIT.BA_ / TEXTEDIT.bin
Encoding:
Text File  |  1992-10-21  |  2.7 KB  |  62 lines

  1. Dim ArrayNum As Integer ' Index value for the menu control array mnuFileArray.
  2. Global FileName As String ' This variable keeps track of the filename information for opening and closing files.
  3. Const MB_YESNO = 4, MB_ICONQUESTION = 32, IDNO = 7, MB_DEFBUTTON2 = 256
  4.  
  5. Sub CloseFile (FileName As String)
  6. Dim F As Integer
  7. On Error GoTo CloseError                ' If there is an error, display the error message below.
  8.     
  9.     If Dir(FileName) <> "" Then         ' File already exists, so ask if overwriting is desired.
  10.         response = MsgBox("Overwrite existing file?", MB_YESNO + MB_QUESTION + MB_DEFBUTTON2)
  11.         If response = IDNO Then Exit Sub
  12.     End If
  13.     F = FreeFile
  14.     Open FileName For Output As F       ' Otherwise, open the file name for output.
  15.     Print #F, frmEditor!txtEdit.Text    ' Print the current text to the opened file.
  16.     Close F                             ' Close the file
  17.     FileName = frmOpenSave!dirOpenSave.Path + "\" + "Untitled" ' Reset the caption of the main form
  18.     Exit Sub
  19. CloseError:
  20.     MsgBox "Error occurred trying to close file, please retry.", 48
  21.     Exit Sub
  22. End Sub
  23.  
  24. Sub DoUnLoadPreCheck (unloadmode As Integer)
  25.     If unloadmode = 0 Or unloadmode = 3 Then
  26.             Unload frmAbout
  27.             Unload frmEditor
  28.             Unload frmOpenSave
  29.             End
  30.     End If
  31. End Sub
  32.  
  33. Sub OpenFile (FileName As String)
  34. Dim F As Integer
  35.     If "Text Editor: " + FileName = frmEditor.Caption Then  ' Avoid opening the file if already loaded.
  36.         Exit Sub
  37.     Else
  38.         On Error GoTo ErrHandler
  39.             F = FreeFile
  40.             Open FileName For Input As F                    ' Open file selected on File Open About.
  41.             frmEditor!txtEdit.Text = Input$(LOF(F), F)
  42.             Close F                                         ' Close file.
  43.             frmEditor!mnuFileItem(3).Enabled = True         ' Enable the Close menu item
  44.             UpdateMenu
  45.             frmEditor.Caption = "Text Editor: " + FileName
  46.             Exit Sub
  47.     End If
  48. ErrHandler:
  49.         MsgBox "Error encountered while trying to open file, please retry.", 48, "Text Editor"
  50.         Close F
  51.         Exit Sub
  52. End Sub
  53.  
  54. Sub UpdateMenu ()
  55.     frmEditor!mnuFileArray(0).Visible = True            ' Make the initial element visible / display separator bar.
  56.     ArrayNum = ArrayNum + 1                             ' Increment index property of control array.
  57.     Load frmEditor!mnuFileArray(ArrayNum)               ' Create a new menu control.
  58.     frmEditor!mnuFileArray(ArrayNum).Caption = FileName ' Set the caption of the new menu item.
  59.     frmEditor!mnuFileArray(ArrayNum).Visible = True     ' Make the new menu item visible.
  60. End Sub
  61.  
  62.