home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch05 / textpad / textpad.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-03-07  |  7.0 KB  |  244 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Simple Text Editor"
  5.    ClientHeight    =   5910
  6.    ClientLeft      =   165
  7.    ClientTop       =   735
  8.    ClientWidth     =   7380
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   5910
  11.    ScaleWidth      =   7380
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.TextBox Editor 
  14.       Height          =   5745
  15.       HideSelection   =   0   'False
  16.       Left            =   45
  17.       MultiLine       =   -1  'True
  18.       ScrollBars      =   2  'Vertical
  19.       TabIndex        =   0
  20.       Top             =   15
  21.       Width           =   7230
  22.    End
  23.    Begin MSComDlg.CommonDialog CommonDialog1 
  24.       Left            =   -15
  25.       Top             =   0
  26.       _ExtentX        =   847
  27.       _ExtentY        =   847
  28.       _Version        =   393216
  29.       FontSize        =   2.54052e-29
  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. Dim OpenFile As String
  104. Private Sub CustomFont_Click()
  105.     CommonDialog1.Flags = cdlCFBoth
  106.     CommonDialog1.ShowFont
  107.     Editor.Font = CommonDialog1.FontName
  108.     Editor.FontBold = CommonDialog1.FontBold
  109.     Editor.FontItalic = CommonDialog1.FontItalic
  110.     Editor.FontSize = CommonDialog1.FontSize
  111. End Sub
  112. Private Sub CustomPage_Click()
  113.     CommonDialog1.ShowColor
  114.     Editor.BackColor = CommonDialog1.Color
  115. End Sub
  116. Private Sub CustomText_Click()
  117. On Error Resume Next
  118.     CommonDialog1.ShowColor
  119.     Editor.ForeColor = CommonDialog1.Color
  120. End Sub
  121. Private Sub EditCopy_Click()
  122.     Clipboard.Clear
  123.     Clipboard.SetText Editor.SelText
  124. End Sub
  125. Private Sub EditCut_Click()
  126.     Clipboard.SetText Editor.SelText
  127.     Editor.SelText = ""
  128. End Sub
  129. Private Sub EditFind_Click()
  130.     Form2.Show
  131. End Sub
  132. Private Sub EditPaste_Click()
  133.     If Clipboard.GetFormat(vbCFText) Then
  134.         Editor.SelText = Clipboard.GetText
  135.     Else
  136.         MsgBox "Invalid Clipboard format."
  137.     End If
  138. End Sub
  139. Private Sub EditSelect_Click()
  140.     Editor.SelStart = 0
  141.     Editor.SelLength = Len(Editor.Text)
  142. End Sub
  143. Private Sub FileExit_Click()
  144.     End
  145. End Sub
  146. Private Sub FileNew_Click()
  147.     Editor.Text = ""
  148.     OpenFile = ""
  149. End Sub
  150. Private Sub FileOpen_Click()
  151. Dim FNum As Integer
  152. Dim txt As String
  153. On Error GoTo FileError
  154.     CommonDialog1.CancelError = True
  155.     CommonDialog1.Flags = cdlOFNFileMustExist
  156.     CommonDialog1.DefaultExt = "TXT"
  157.     CommonDialog1.Filter = "Text files|*.TXT|All files|*.*"
  158.     CommonDialog1.ShowOpen
  159.     FNum = FreeFile
  160.     Open CommonDialog1.FileName For Input As #1
  161.     txt = Input(LOF(FNum), #FNum)
  162.     Close #FNum
  163.     Editor.Text = txt
  164.     OpenFile = CommonDialog1.FileName
  165.     Exit Sub
  166. FileError:
  167.     If Err.Number = cdlCancel Then Exit Sub
  168.     MsgBox "Unkown error while opening file " & CommonDialog1.FileName
  169.     OpenFile = ""
  170. End Sub
  171. Private Sub FileSave_Click()
  172. Dim FNum As Integer
  173. Dim txt As String
  174.     If OpenFile = "" Then
  175.         FileSaveAs_Click
  176.         Exit Sub
  177.     End If
  178. On Error GoTo FileError
  179.     FNum = FreeFile
  180.     Open OpenFile For Output As #1
  181.     Print #FNum, Editor.Text
  182.     Close #FNum
  183.     Exit Sub
  184. FileError:
  185.     If Err.Number = cdlCancel Then Exit Sub
  186.     MsgBox "Unkown error while saving file " & OpenFile
  187.     OpenFile = ""
  188. End Sub
  189. Private Sub FileSaveAs_Click()
  190. Dim FNum As Integer
  191. Dim txt As String
  192. On Error GoTo FileError
  193.     CommonDialog1.CancelError = True
  194.     CommonDialog1.Flags = cdlOFNOverwritePrompt
  195.     CommonDialog1.DefaultExt = "TXT"
  196.     CommonDialog1.Filter = "Text files|*.TXT|All files|*.*"
  197.     CommonDialog1.ShowSave
  198.     FNum = FreeFile
  199.     Open CommonDialog1.FileName For Output As #1
  200.     Print #FNum, Editor.Text
  201.     Close #FNum
  202.     OpenFile = CommonDialog1.FileName
  203.     Exit Sub
  204. FileError:
  205.     If Err.Number = cdlCancel Then Exit Sub
  206.     MsgBox "Unkown error while saving file " & CommonDialog1.FileName
  207.     OpenFile = ""
  208. End Sub
  209. Private Sub Form_Resize()
  210.     Editor.Width = Form1.Width - 15 * Screen.TwipsPerPixelX
  211.     Editor.Height = Form1.Height - 50 * Screen.TwipsPerPixelY
  212. End Sub
  213. Private Sub ProcessLower_Click()
  214. Dim Sel1 As Integer, Sel2 As Integer
  215.     Sel1 = Editor.SelStart
  216.     Sel2 = Editor.SelLength
  217.     Editor.SelText = LCase$(Editor.SelText)
  218.     Editor.SelStart = Sel1
  219.     Editor.SelLength = Sel2
  220. End Sub
  221. Private Sub ProcessNumber_Click()
  222. Dim tmpText As String, tmpLine As String
  223. Dim firstChar As Integer, lastChar As Integer
  224. Dim currentLine As Integer
  225. firstChar = 1
  226. currentLine = 1
  227. lastChar = InStr(Editor.Text, Chr$(10))
  228. While lastChar > 0
  229.     tmpLine = Format$(currentLine, "000") & "  " & Mid$(Editor.Text, firstChar, lastChar - firstChar + 1)
  230.     currentLine = currentLine + 1
  231.     firstChar = lastChar + 1
  232.     lastChar = InStr(firstChar, Editor.Text, Chr$(10))
  233.     tmpText = tmpText + tmpLine
  234. Editor.Text = tmpText
  235. End Sub
  236. Private Sub ProcessUpper_Click()
  237. Dim Sel1, Sel2 As Integer
  238.     Sel1 = Editor.SelStart
  239.     Sel2 = Editor.SelLength
  240.     Editor.SelText = UCase$(Editor.SelText)
  241.     Editor.SelStart = Sel1
  242.     Editor.SelLength = Sel2
  243. End Sub
  244.