home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch09 / mdiedit / editor.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-02-20  |  6.8 KB  |  234 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Simple Text Editor"
  5.    ClientHeight    =   6150
  6.    ClientLeft      =   165
  7.    ClientTop       =   450
  8.    ClientWidth     =   7650
  9.    LinkTopic       =   "Form1"
  10.    MDIChild        =   -1  'True
  11.    ScaleHeight     =   6150
  12.    ScaleWidth      =   7650
  13.    Begin VB.TextBox Editor 
  14.       Height          =   5745
  15.       HideSelection   =   0   'False
  16.       Left            =   225
  17.       MultiLine       =   -1  'True
  18.       ScrollBars      =   2  'Vertical
  19.       TabIndex        =   0
  20.       Top             =   210
  21.       Width           =   7230
  22.    End
  23.    Begin MSComDlg.CommonDialog CommonDialog1 
  24.       Left            =   0
  25.       Top             =   0
  26.       _ExtentX        =   847
  27.       _ExtentY        =   847
  28.       _Version        =   327680
  29.       FontSize        =   1.17491e-38
  30.    End
  31.    Begin VB.Menu FileMenu 
  32.       Caption         =   "File"
  33.       Begin VB.Menu FileNew 
  34.          Caption         =   "New"
  35.       End
  36.       Begin VB.Menu FileOpen 
  37.          Caption         =   "Open"
  38.       End
  39.       Begin VB.Menu FileSave 
  40.          Caption         =   "Save"
  41.       End
  42.       Begin VB.Menu FileSaveAs 
  43.          Caption         =   "Save As"
  44.       End
  45.       Begin VB.Menu FileSeparator 
  46.          Caption         =   "-"
  47.       End
  48.       Begin VB.Menu FileExit 
  49.          Caption         =   "Exit"
  50.       End
  51.    End
  52.    Begin VB.Menu EditMenu 
  53.       Caption         =   "Edit"
  54.       Begin VB.Menu EditCopy 
  55.          Caption         =   "Copy"
  56.       End
  57.       Begin VB.Menu EditCut 
  58.          Caption         =   "Cut"
  59.       End
  60.       Begin VB.Menu EditPaste 
  61.          Caption         =   "Paste"
  62.       End
  63.       Begin VB.Menu EditSelect 
  64.          Caption         =   "Select All"
  65.       End
  66.       Begin VB.Menu EditSeparator 
  67.          Caption         =   "-"
  68.       End
  69.       Begin VB.Menu EditFind 
  70.          Caption         =   "Find"
  71.       End
  72.    End
  73.    Begin VB.Menu ProcessMenu 
  74.       Caption         =   "Process"
  75.       Begin VB.Menu ProcessUpper 
  76.          Caption         =   "Upper Case"
  77.       End
  78.       Begin VB.Menu ProcessLower 
  79.          Caption         =   "Lower Case"
  80.       End
  81.       Begin VB.Menu ProcessNumber 
  82.          Caption         =   "Number Lines"
  83.       End
  84.    End
  85.    Begin VB.Menu CustomMenu 
  86.       Caption         =   "Customize"
  87.       Begin VB.Menu CustomFont 
  88.          Caption         =   "Font"
  89.       End
  90.       Begin VB.Menu CustomPage 
  91.          Caption         =   "Page Color"
  92.       End
  93.       Begin VB.Menu CustomText 
  94.          Caption         =   "Text Color"
  95.       End
  96.    End
  97. Attribute VB_Name = "Form1"
  98. Attribute VB_GlobalNameSpace = False
  99. Attribute VB_Creatable = False
  100. Attribute VB_PredeclaredId = True
  101. Attribute VB_Exposed = False
  102. Option Explicit
  103. Private Sub CustomFont_Click()
  104.     CommonDialog1.Flags = cdlCFBoth
  105.     CommonDialog1.ShowFont
  106.     Editor.Font = CommonDialog1.FontName
  107.     Editor.FontBold = CommonDialog1.FontBold
  108.     Editor.FontItalic = CommonDialog1.FontItalic
  109.     Editor.FontSize = CommonDialog1.FontSize
  110. End Sub
  111. Private Sub CustomPage_Click()
  112.     CommonDialog1.ShowColor
  113.     Editor.BackColor = CommonDialog1.Color
  114. End Sub
  115. Private Sub CustomText_Click()
  116.     CommonDialog1.ShowColor
  117.     Editor.ForeColor = CommonDialog1.Color
  118. End Sub
  119. Private Sub EditCopy_Click()
  120.     Clipboard.SetText Editor.SelText
  121. End Sub
  122. Private Sub EditCut_Click()
  123.     Clipboard.SetText Editor.SelText
  124.     Editor.SelText = ""
  125. End Sub
  126. Private Sub EditFind_Click()
  127.     Form2.Show
  128. End Sub
  129. Private Sub EditPaste_Click()
  130.     Editor.SelText = Clipboard.GetText
  131. End Sub
  132. Private Sub EditSelect_Click()
  133.     Editor.SelStart = 0
  134.     Editor.SelLength = Len(Editor.Text)
  135. End Sub
  136. Private Sub FileExit_Click()
  137.     Unload MDIForm1
  138.     End
  139. End Sub
  140. Private Sub FileNew_Click()
  141.     MDIForm1.MDINew_Click
  142. End Sub
  143. Private Sub FileOpen_Click()
  144.     MDIForm1.MDIOpen_Click
  145. End Sub
  146. Private Sub FileSave_Click()
  147. Dim FNum As Integer
  148. Dim txt As String
  149.     If OpenFile = "" Then
  150.         FileSaveAs_Click
  151.         Exit Sub
  152.     End If
  153. On Error GoTo FileError
  154.     FNum = FreeFile
  155.     Open OpenFiles(currentDocument) For Output As #1
  156.     Print #FNum, Editor.Text
  157.     Close #FNum
  158.     Exit Sub
  159. FileError:
  160.     If Err.Number = cdlCancel Then Exit Sub
  161.     MsgBox "Unkown error while saving file " & OpenFiles(currentDocument)
  162.     OpenFiles(currentDocument) = ""
  163. End Sub
  164. Private Sub FileSaveAs_Click()
  165. Dim FNum As Integer
  166. Dim txt As String
  167. On Error GoTo FileError
  168.     CommonDialog1.CancelError = True
  169.     CommonDialog1.Flags = cdlOFNOverwritePrompt
  170.     CommonDialog1.DefaultExt = "TXT"
  171.     CommonDialog1.Filter = "Text files|*.TXT|All files|*.*"
  172.     CommonDialog1.ShowSave
  173.     FNum = FreeFile
  174.     Open CommonDialog1.filename For Output As #1
  175.     Print #FNum, Editor.Text
  176.     Close #FNum
  177.     OpenFiles(currentDocument) = CommonDialog1.filename
  178.     DocumentForms(currentDocument).Caption = OpenFiles(currentDocument)
  179.     Exit Sub
  180. FileError:
  181.     If Err.Number = cdlCancel Then Exit Sub
  182.     MsgBox "Unkown error while saving file " & CommonDialog1.filename
  183.     OpenFiles(currentDocument) = ""
  184. End Sub
  185. Private Sub Form_GotFocus()
  186.     currentDocument = Me.Tag
  187. End Sub
  188. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  189. Dim reply As Integer
  190.     reply = MsgBox("Are you sure you want to close the document " & Me.Tag, _
  191.     vbYesNoCancel + vbInformation)
  192.     If reply = vbCancel Then
  193.         Cancel = True
  194.     ElseIf reply = vbYes Then Exit Sub
  195.     Else
  196.         FileSaveAs_Click
  197.     End If
  198. End Sub
  199. Private Sub Form_Resize()
  200.     Editor.Width = Me.Width - 600
  201.     Editor.Height = Me.Height - 1100
  202. End Sub
  203. Private Sub ProcessLower_Click()
  204. Dim Sel1, Sel2 As Integer
  205.     Sel1 = Editor.SelStart
  206.     Sel2 = Editor.SelLength
  207.     Editor.SelText = LCase$(Editor.SelText)
  208.     Editor.SelStart = Sel1
  209.     Editor.SelLength = Sel2
  210. End Sub
  211. Private Sub ProcessNumber_Click()
  212. Dim tmpText, tmpLine As String
  213. Dim firstChar, lastChar As Integer
  214. Dim currentLine As Integer
  215. firstChar = 1
  216. currentLine = 1
  217. lastChar = InStr(Editor.Text, Chr$(10))
  218. While lastChar > 0
  219.     tmpLine = Format$(currentLine, "000") & "  " & Mid$(Editor.Text, firstChar, lastChar - firstChar + 1)
  220.     currentLine = currentLine + 1
  221.     firstChar = lastChar + 1
  222.     lastChar = InStr(firstChar, Editor.Text, Chr$(10))
  223.     tmpText = tmpText + tmpLine
  224. Editor.Text = tmpText
  225. End Sub
  226. Private Sub ProcessUpper_Click()
  227. Dim Sel1, Sel2 As Integer
  228.     Sel1 = Editor.SelStart
  229.     Sel2 = Editor.SelLength
  230.     Editor.SelText = UCase$(Editor.SelText)
  231.     Editor.SelStart = Sel1
  232.     Editor.SelLength = Sel2
  233. End Sub
  234.