home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
- Begin VB.Form EditorForm
- Caption = "Simple Text Editor"
- ClientHeight = 5760
- ClientLeft = 165
- ClientTop = 450
- ClientWidth = 7260
- LinkTopic = "Form1"
- MDIChild = -1 'True
- ScaleHeight = 5760
- ScaleWidth = 7260
- Begin VB.TextBox Editor
- Height = 5745
- HideSelection = 0 'False
- Left = 0
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 0
- Top = 0
- Width = 7230
- End
- Begin MSComDlg.CommonDialog CommonDialog1
- Left = 0
- Top = 0
- _ExtentX = 847
- _ExtentY = 847
- _Version = 393216
- FontSize = 1.17491e-38
- End
- Begin VB.Menu FileMenu
- Caption = "File"
- Begin VB.Menu FileNew
- Caption = "New"
- End
- Begin VB.Menu FileOpen
- Caption = "Open"
- End
- Begin VB.Menu FileSave
- Caption = "Save"
- End
- Begin VB.Menu FileSaveAs
- Caption = "Save As"
- End
- Begin VB.Menu FileSeparator
- Caption = "-"
- End
- Begin VB.Menu FileExit
- Caption = "Exit"
- End
- End
- Begin VB.Menu EditMenu
- Caption = "Edit"
- Begin VB.Menu EditCopy
- Caption = "Copy"
- End
- Begin VB.Menu EditCut
- Caption = "Cut"
- End
- Begin VB.Menu EditPaste
- Caption = "Paste"
- End
- Begin VB.Menu EditSelect
- Caption = "Select All"
- End
- Begin VB.Menu EditSeparator
- Caption = "-"
- End
- Begin VB.Menu EditFind
- Caption = "Find"
- End
- End
- Begin VB.Menu ProcessMenu
- Caption = "Process"
- Begin VB.Menu ProcessUpper
- Caption = "Upper Case"
- End
- Begin VB.Menu ProcessLower
- Caption = "Lower Case"
- End
- Begin VB.Menu ProcessNumber
- Caption = "Number Lines"
- End
- End
- Begin VB.Menu CustomMenu
- Caption = "Customize"
- Begin VB.Menu CustomFont
- Caption = "Font"
- End
- Begin VB.Menu CustomPage
- Caption = "Page Color"
- End
- Begin VB.Menu CustomText
- Caption = "Text Color"
- End
- End
- Attribute VB_Name = "EditorForm"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- ' ******************************
- ' ******************************
- ' ** MASTERING VB6 **
- ' ** by Evangelos Petroutos **
- ' ** SYBEX, 1998 **
- ' ******************************
- ' ******************************
- Option Explicit
- Private Sub CustomFont_Click()
- CommonDialog1.Flags = cdlCFBoth
- CommonDialog1.ShowFont
- Editor.Font = CommonDialog1.FontName
- Editor.FontBold = CommonDialog1.FontBold
- Editor.FontItalic = CommonDialog1.FontItalic
- Editor.FontSize = CommonDialog1.FontSize
- End Sub
- Private Sub CustomPage_Click()
- CommonDialog1.ShowColor
- Editor.BackColor = CommonDialog1.Color
- End Sub
- Private Sub CustomText_Click()
- CommonDialog1.ShowColor
- Editor.ForeColor = CommonDialog1.Color
- End Sub
- Private Sub EditCopy_Click()
- Clipboard.SetText Editor.SelText
- End Sub
- Private Sub EditCut_Click()
- Clipboard.SetText Editor.SelText
- Editor.SelText = ""
- End Sub
- Private Sub EditFind_Click()
- Form2.Show
- End Sub
- Private Sub EditPaste_Click()
- Editor.SelText = Clipboard.GetText
- End Sub
- Private Sub EditSelect_Click()
- Editor.SelStart = 0
- Editor.SelLength = Len(Editor.Text)
- End Sub
- Private Sub FileExit_Click()
- Unload MDIForm1
- End
- End Sub
- Private Sub FileNew_Click()
- MDIForm1.MDINew_Click
- End Sub
- Private Sub FileOpen_Click()
- MDIForm1.MDIOpen_Click
- ' CALL THE FORM'S RESIZE METHOD TO MAKE SURE
- ' THE VERTICAL SCROLLBAR IS VISIBLE
- Form_Resize
- End Sub
- Private Sub FileSave_Click()
- Dim FNum As Integer
- Dim txt As String
- If OpenFile = "" Then
- FileSaveAs_Click
- Exit Sub
- End If
- On Error GoTo FileError
- FNum = FreeFile
- Open OpenFiles(currentDocument) For Output As #1
- Print #FNum, Editor.Text
- Close #FNum
- Exit Sub
- FileError:
- If Err.Number = cdlCancel Then Exit Sub
- MsgBox "Unkown error while saving file " & OpenFiles(currentDocument)
- OpenFiles(currentDocument) = ""
- End Sub
- Private Sub FileSaveAs_Click()
- Dim FNum As Integer
- Dim txt As String
- On Error GoTo FileError
- CommonDialog1.CancelError = True
- CommonDialog1.Flags = cdlOFNOverwritePrompt
- CommonDialog1.DefaultExt = "TXT"
- CommonDialog1.Filter = "Text files|*.TXT|All files|*.*"
- CommonDialog1.ShowSave
- FNum = FreeFile
- Open CommonDialog1.FileName For Output As #1
- Print #FNum, Editor.Text
- Close #FNum
- OpenFiles(currentDocument) = CommonDialog1.FileName
- DocumentForms(currentDocument).Caption = OpenFiles(currentDocument)
- Exit Sub
- FileError:
- If Err.Number = cdlCancel Then Exit Sub
- MsgBox "Unkown error while saving file " & CommonDialog1.FileName
- OpenFiles(currentDocument) = ""
- End Sub
- Private Sub Form_GotFocus()
- currentDocument = Me.Tag
- End Sub
- Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
- Dim reply As Integer
- reply = MsgBox("Are you sure you want to close the document " & Me.Tag, _
- vbYesNoCancel + vbInformation)
- If reply = vbCancel Then
- Cancel = True
- ElseIf reply = vbYes Then Exit Sub
- Else
- FileSaveAs_Click
- End If
- End Sub
- ' THE RESIZE METHOD IS PUBLIC BECAUSE IT MUST
- ' BE CALLED FROM OUTSIDE THIS FORM
- Public Sub Form_Resize()
- DocumentForms(currentDocument).Editor.Width = DocumentForms(currentDocument).Width - 10 * Screen.TwipsPerPixelX
- DocumentForms(currentDocument).Editor.Height = DocumentForms(currentDocument).Height - 30 * Screen.TwipsPerPixelX
- End Sub
- Private Sub ProcessLower_Click()
- Dim Sel1 As Integer, Sel2 As Integer
- Sel1 = Editor.SelStart
- Sel2 = Editor.SelLength
- Editor.SelText = LCase$(Editor.SelText)
- Editor.SelStart = Sel1
- Editor.SelLength = Sel2
- End Sub
- Private Sub ProcessNumber_Click()
- Dim tmpText As String, tmpLine As String
- Dim firstChar As Integer, lastChar As Integer
- Dim currentLine As Integer
- firstChar = 1
- currentLine = 1
- lastChar = InStr(Editor.Text, Chr$(10))
- While lastChar > 0
- tmpLine = Format$(currentLine, "000") & " " & Mid$(Editor.Text, firstChar, lastChar - firstChar + 1)
- currentLine = currentLine + 1
- firstChar = lastChar + 1
- lastChar = InStr(firstChar, Editor.Text, Chr$(10))
- tmpText = tmpText + tmpLine
- Editor.Text = tmpText
- End Sub
- Private Sub ProcessUpper_Click()
- Dim Sel1 As Integer, Sel2 As Integer
- Sel1 = Editor.SelStart
- Sel2 = Editor.SelLength
- Editor.SelText = UCase$(Editor.SelText)
- Editor.SelStart = Sel1
- Editor.SelLength = Sel2
- End Sub
-