home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch10 / mdipad / mdiform.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-03-01  |  3.0 KB  |  96 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.MDIForm MDIForm1 
  4.    AutoShowChildren=   0   'False
  5.    BackColor       =   &H8000000C&
  6.    Caption         =   "MDIEditor"
  7.    ClientHeight    =   4905
  8.    ClientLeft      =   165
  9.    ClientTop       =   735
  10.    ClientWidth     =   6840
  11.    LinkTopic       =   "MDIForm1"
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin MSComDlg.CommonDialog CommonDialog1 
  14.       Left            =   5550
  15.       Top             =   360
  16.       _ExtentX        =   847
  17.       _ExtentY        =   847
  18.       _Version        =   393216
  19.       FontSize        =   1.17491e-38
  20.    End
  21.    Begin VB.Menu MDIFileMenu 
  22.       Caption         =   "File"
  23.       Begin VB.Menu MDINew 
  24.          Caption         =   "New Document"
  25.       End
  26.       Begin VB.Menu MDIOpen 
  27.          Caption         =   "Open Document"
  28.       End
  29.       Begin VB.Menu MDIExit 
  30.          Caption         =   "Exit"
  31.       End
  32.    End
  33. Attribute VB_Name = "MDIForm1"
  34. Attribute VB_GlobalNameSpace = False
  35. Attribute VB_Creatable = False
  36. Attribute VB_PredeclaredId = True
  37. Attribute VB_Exposed = False
  38. Option Explicit
  39. Function FindFree() As Integer
  40. Dim i As Integer
  41.     For i = 0 To 9
  42.         If DocumentForms(i).Tag = "" Then
  43.             FindFree = i
  44.             Exit Function
  45.         End If
  46.     Next
  47. End Function
  48. Private Sub MDIExit_Click()
  49.     End
  50. End Sub
  51. Public Sub MDINew_Click()
  52. Dim windex As Integer
  53.     windex = FindFree()
  54.     If windex = -1 Then
  55.         MsgBox "You must close one of the documents before another one can be opened"
  56.         Exit Sub
  57.     End If
  58.     Load DocumentForms(windex)
  59.     DocumentForms(windex).Caption = "New Document"
  60.     DocumentForms(windex).Tag = windex
  61.     DocumentForms(windex).Show
  62.     currentDocument = windex
  63. End Sub
  64. Public Sub MDIOpen_Click()
  65. Dim FNum As Integer
  66. Dim txt As String
  67. Dim windex As Integer
  68.     windex = FindFree()
  69.     If windex = -1 Then
  70.         MsgBox "You must close one of the documents before another one can be opened"
  71.         Exit Sub
  72.     End If
  73.     Load DocumentForms(windex)
  74.     DocumentForms(windex).Show
  75.     currentDocument = windex
  76. On Error GoTo FileError
  77.     CommonDialog1.CancelError = True
  78.     CommonDialog1.Flags = cdlOFNFileMustExist
  79.     CommonDialog1.DefaultExt = "TXT"
  80.     CommonDialog1.Filter = "Text files|*.TXT|All files|*.*"
  81.     CommonDialog1.ShowOpen
  82.     FNum = FreeFile
  83.     Open CommonDialog1.FileName For Input As #1
  84.     txt = Input(LOF(FNum), #FNum)
  85.     Close #FNum
  86.     DocumentForms(currentDocument).Editor.Text = txt
  87.     OpenFiles(currentDocument) = CommonDialog1.FileName
  88.     DocumentForms(currentDocument).Tag = OpenFiles(currentDocument)
  89.     DocumentForms(currentDocument).Caption = OpenFiles(currentDocument)
  90.     Exit Sub
  91. FileError:
  92.     If Err.Number = cdlCancel Then Exit Sub
  93.     MsgBox "Unkown error while opening file " & CommonDialog1.FileName
  94.     OpenFiles(currentDocument) = ""
  95. End Sub
  96.