home *** CD-ROM | disk | FTP | other *** search
/ On Hand / On_Hand_From_Softbank_1994_Release_2_Disc_2_1994.iso / 00202 / s / disk1 / textedit.ba_ / textedit.bin
Text File  |  1993-04-28  |  3KB  |  70 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 = "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.             End
  29.     End If
  30. End Sub
  31.  
  32. Sub OpenFile (Filename As String)
  33. Dim F As Integer
  34.     If "Text Editor: " + Filename = frmEditor.Caption Then  ' Avoid opening the file if already loaded.
  35.         Exit Sub
  36.     Else
  37.         On Error GoTo ErrHandler
  38.             F = FreeFile
  39.             Open Filename For Input As F                    ' Open file selected on File Open About.
  40.             frmEditor!txtEdit.Text = Input$(LOF(F), F)
  41.             Close F                                         ' Close file.
  42.             frmEditor!mnuFileItem(3).Enabled = True         ' Enable the Close menu item
  43.             UpdateMenu
  44.             frmEditor.Caption = "Text Editor: " + Filename
  45.             Exit Sub
  46.     End If
  47. ErrHandler:
  48.         MsgBox "Error encountered while trying to open file, please retry.", 48, "Text Editor"
  49.         Close F
  50.         Exit Sub
  51. End Sub
  52.  
  53. Sub UpdateMenu ()
  54.     frmEditor!mnuFileArray(0).Visible = True            ' Make the initial element visible / display separator bar.
  55.     ArrayNum = ArrayNum + 1                             ' Increment index property of control array.
  56.     ' Check to see if Filename is already on menu list.
  57.     For i = 0 To ArrayNum - 1
  58.         If frmEditor!mnuFileArray(i).Caption = Filename Then
  59.             ArrayNum = ArrayNum - 1
  60.             Exit Sub
  61.         End If
  62.     Next i
  63.     
  64.     ' If filename is not on menu list, add menu item.
  65.     Load frmEditor!mnuFileArray(ArrayNum)               ' Create a new menu control.
  66.     frmEditor!mnuFileArray(ArrayNum).Caption = Filename ' Set the caption of the new menu item.
  67.     frmEditor!mnuFileArray(ArrayNum).Visible = True     ' Make the new menu item visible.
  68. End Sub
  69.  
  70.