home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch05 / textpad / textpad.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-20  |  6.8 KB  |  237 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       =   735
  8.    ClientWidth     =   7650
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   6150
  11.    ScaleWidth      =   7650
  12.    StartUpPosition =   3  'Windows Default
  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.       FontSize        =   2.54052e-29
  29.    End
  30.    Begin VB.Menu FileMenu 
  31.       Caption         =   "File"
  32.       Begin VB.Menu FileNew 
  33.          Caption         =   "New"
  34.       End
  35.       Begin VB.Menu FileOpen 
  36.          Caption         =   "Open"
  37.       End
  38.       Begin VB.Menu FileSave 
  39.          Caption         =   "Save"
  40.       End
  41.       Begin VB.Menu FileSaveAs 
  42.          Caption         =   "Save As"
  43.       End
  44.       Begin VB.Menu FileSeparator 
  45.          Caption         =   "-"
  46.       End
  47.       Begin VB.Menu FileExit 
  48.          Caption         =   "Exit"
  49.       End
  50.    End
  51.    Begin VB.Menu EditMenu 
  52.       Caption         =   "Edit"
  53.       Begin VB.Menu EditCopy 
  54.          Caption         =   "Copy"
  55.       End
  56.       Begin VB.Menu EditCut 
  57.          Caption         =   "Cut"
  58.       End
  59.       Begin VB.Menu EditPaste 
  60.          Caption         =   "Paste"
  61.       End
  62.       Begin VB.Menu EditSelect 
  63.          Caption         =   "Select All"
  64.       End
  65.       Begin VB.Menu EditSeparator 
  66.          Caption         =   "-"
  67.       End
  68.       Begin VB.Menu EditFind 
  69.          Caption         =   "Find"
  70.       End
  71.    End
  72.    Begin VB.Menu ProcessMenu 
  73.       Caption         =   "Process"
  74.       Begin VB.Menu ProcessUpper 
  75.          Caption         =   "Upper Case"
  76.       End
  77.       Begin VB.Menu ProcessLower 
  78.          Caption         =   "Lower Case"
  79.       End
  80.       Begin VB.Menu ProcessNumber 
  81.          Caption         =   "Number Lines"
  82.       End
  83.    End
  84.    Begin VB.Menu CustomMenu 
  85.       Caption         =   "Customize"
  86.       Begin VB.Menu CustomFont 
  87.          Caption         =   "Font"
  88.       End
  89.       Begin VB.Menu CustomPage 
  90.          Caption         =   "Page Color"
  91.       End
  92.       Begin VB.Menu CustomText 
  93.          Caption         =   "Text Color"
  94.       End
  95.    End
  96. Attribute VB_Name = "Form1"
  97. Attribute VB_GlobalNameSpace = False
  98. Attribute VB_Creatable = False
  99. Attribute VB_PredeclaredId = True
  100. Attribute VB_Exposed = False
  101. Option Explicit
  102. Dim OpenFile As String
  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.     End
  138. End Sub
  139. Private Sub FileNew_Click()
  140.     Editor.Text = ""
  141.     OpenFile = ""
  142. End Sub
  143. Private Sub FileOpen_Click()
  144. Dim FNum As Integer
  145. Dim txt As String
  146. On Error GoTo FileError
  147.     CommonDialog1.CancelError = True
  148.     CommonDialog1.Flags = cdlOFNFileMustExist
  149.     CommonDialog1.DefaultExt = "TXT"
  150.     CommonDialog1.Filter = "Text files|*.TXT|All files|*.*"
  151.     CommonDialog1.ShowOpen
  152.     FNum = FreeFile
  153.     Open CommonDialog1.filename For Input As #1
  154.     txt = Input(LOF(FNum), #FNum)
  155.     Close #FNum
  156.     Editor.Text = txt
  157.     OpenFile = CommonDialog1.filename
  158.     Exit Sub
  159. FileError:
  160.     If Err.Number = cdlCancel Then Exit Sub
  161.     MsgBox "Unkown error while opening file " & CommonDialog1.filename
  162.     OpenFile = ""
  163. End Sub
  164. Private Sub FileSave_Click()
  165. Dim FNum As Integer
  166. Dim txt As String
  167.     If OpenFile = "" Then
  168.         FileSaveAs_Click
  169.         Exit Sub
  170.     End If
  171. On Error GoTo FileError
  172.     FNum = FreeFile
  173.     Open OpenFile For Output As #1
  174.     Print #FNum, Editor.Text
  175.     Close #FNum
  176.     Exit Sub
  177. FileError:
  178.     If Err.Number = cdlCancel Then Exit Sub
  179.     MsgBox "Unkown error while saving file " & OpenFile
  180.     OpenFile = ""
  181. End Sub
  182. Private Sub FileSaveAs_Click()
  183. Dim FNum As Integer
  184. Dim txt As String
  185. On Error GoTo FileError
  186.     CommonDialog1.CancelError = True
  187.     CommonDialog1.Flags = cdlOFNOverwritePrompt
  188.     CommonDialog1.DefaultExt = "TXT"
  189.     CommonDialog1.Filter = "Text files|*.TXT|All files|*.*"
  190.     CommonDialog1.ShowSave
  191.     FNum = FreeFile
  192.     Open CommonDialog1.filename For Output As #1
  193.     Print #FNum, Editor.Text
  194.     Close #FNum
  195.     OpenFile = CommonDialog1.filename
  196.     Exit Sub
  197. FileError:
  198.     If Err.Number = cdlCancel Then Exit Sub
  199.     MsgBox "Unkown error while saving file " & CommonDialog1.filename
  200.     OpenFile = ""
  201. End Sub
  202. Private Sub Form_Resize()
  203.     Editor.Width = Form1.Width - 600
  204.     Editor.Height = Form1.Height - 1100
  205. End Sub
  206. Private Sub ProcessLower_Click()
  207. Dim Sel1, Sel2 As Integer
  208.     Sel1 = Editor.SelStart
  209.     Sel2 = Editor.SelLength
  210.     Editor.SelText = LCase$(Editor.SelText)
  211.     Editor.SelStart = Sel1
  212.     Editor.SelLength = Sel2
  213. End Sub
  214. Private Sub ProcessNumber_Click()
  215. Dim tmpText, tmpLine As String
  216. Dim firstChar, lastChar As Integer
  217. Dim currentLine As Integer
  218. firstChar = 1
  219. currentLine = 1
  220. lastChar = InStr(Editor.Text, Chr$(10))
  221. While lastChar > 0
  222.     tmpLine = Format$(currentLine, "000") & "  " & Mid$(Editor.Text, firstChar, lastChar - firstChar + 1)
  223.     currentLine = currentLine + 1
  224.     firstChar = lastChar + 1
  225.     lastChar = InStr(firstChar, Editor.Text, Chr$(10))
  226.     tmpText = tmpText + tmpLine
  227. Editor.Text = tmpText
  228. End Sub
  229. Private Sub ProcessUpper_Click()
  230. Dim Sel1, Sel2 As Integer
  231.     Sel1 = Editor.SelStart
  232.     Sel2 = Editor.SelLength
  233.     Editor.SelText = UCase$(Editor.SelText)
  234.     Editor.SelStart = Sel1
  235.     Editor.SelLength = Sel2
  236. End Sub
  237.