home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch07 / rtfpad / search.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  1997-02-20  |  8.4 KB  |  263 lines

  1. VERSION 5.00
  2. Begin VB.Form Form2 
  3.    Caption         =   "Search & Replace"
  4.    ClientHeight    =   1980
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   6780
  8.    LinkTopic       =   "Form2"
  9.    ScaleHeight     =   1980
  10.    ScaleWidth      =   6780
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.TextBox Text2 
  13.       BeginProperty Font 
  14.          Name            =   "Times New Roman"
  15.          Size            =   9
  16.          Charset         =   0
  17.          Weight          =   400
  18.          Underline       =   0   'False
  19.          Italic          =   0   'False
  20.          Strikethrough   =   0   'False
  21.       EndProperty
  22.       Height          =   285
  23.       Left            =   1740
  24.       TabIndex        =   8
  25.       Top             =   660
  26.       Width           =   2100
  27.    End
  28.    Begin VB.TextBox Text1 
  29.       BeginProperty Font 
  30.          Name            =   "Times New Roman"
  31.          Size            =   9
  32.          Charset         =   0
  33.          Weight          =   400
  34.          Underline       =   0   'False
  35.          Italic          =   0   'False
  36.          Strikethrough   =   0   'False
  37.       EndProperty
  38.       Height          =   285
  39.       Left            =   1740
  40.       TabIndex        =   7
  41.       Top             =   195
  42.       Width           =   2115
  43.    End
  44.    Begin VB.CheckBox Check2 
  45.       Caption         =   "Whole word only"
  46.       BeginProperty Font 
  47.          Name            =   "MS Sans Serif"
  48.          Size            =   9.75
  49.          Charset         =   0
  50.          Weight          =   400
  51.          Underline       =   0   'False
  52.          Italic          =   0   'False
  53.          Strikethrough   =   0   'False
  54.       EndProperty
  55.       Height          =   240
  56.       Left            =   210
  57.       TabIndex        =   6
  58.       Top             =   1575
  59.       Width           =   2040
  60.    End
  61.    Begin VB.CheckBox Check1 
  62.       Caption         =   "Case sensitive"
  63.       BeginProperty Font 
  64.          Name            =   "MS Sans Serif"
  65.          Size            =   9.75
  66.          Charset         =   0
  67.          Weight          =   400
  68.          Underline       =   0   'False
  69.          Italic          =   0   'False
  70.          Strikethrough   =   0   'False
  71.       EndProperty
  72.       Height          =   240
  73.       Left            =   210
  74.       TabIndex        =   5
  75.       Top             =   1275
  76.       Width           =   2040
  77.    End
  78.    Begin VB.CommandButton Command5 
  79.       Cancel          =   -1  'True
  80.       Caption         =   "Cancel"
  81.       BeginProperty Font 
  82.          Name            =   "MS Sans Serif"
  83.          Size            =   9.75
  84.          Charset         =   0
  85.          Weight          =   400
  86.          Underline       =   0   'False
  87.          Italic          =   0   'False
  88.          Strikethrough   =   0   'False
  89.       EndProperty
  90.       Height          =   480
  91.       Left            =   5460
  92.       TabIndex        =   4
  93.       Top             =   1335
  94.       Width           =   1245
  95.    End
  96.    Begin VB.CommandButton ReplaceAllButton 
  97.       Caption         =   "Replace All"
  98.       Enabled         =   0   'False
  99.       BeginProperty Font 
  100.          Name            =   "MS Sans Serif"
  101.          Size            =   9.75
  102.          Charset         =   0
  103.          Weight          =   400
  104.          Underline       =   0   'False
  105.          Italic          =   0   'False
  106.          Strikethrough   =   0   'False
  107.       EndProperty
  108.       Height          =   480
  109.       Left            =   5430
  110.       TabIndex        =   3
  111.       Top             =   630
  112.       Width           =   1275
  113.    End
  114.    Begin VB.CommandButton ReplaceButton 
  115.       Caption         =   "Replace"
  116.       Enabled         =   0   'False
  117.       BeginProperty Font 
  118.          Name            =   "MS Sans Serif"
  119.          Size            =   9.75
  120.          Charset         =   0
  121.          Weight          =   400
  122.          Underline       =   0   'False
  123.          Italic          =   0   'False
  124.          Strikethrough   =   0   'False
  125.       EndProperty
  126.       Height          =   480
  127.       Left            =   4065
  128.       TabIndex        =   2
  129.       Top             =   600
  130.       Width           =   1215
  131.    End
  132.    Begin VB.CommandButton FindNextButton 
  133.       Caption         =   "Find Again"
  134.       BeginProperty Font 
  135.          Name            =   "MS Sans Serif"
  136.          Size            =   9.75
  137.          Charset         =   0
  138.          Weight          =   400
  139.          Underline       =   0   'False
  140.          Italic          =   0   'False
  141.          Strikethrough   =   0   'False
  142.       EndProperty
  143.       Height          =   480
  144.       Left            =   5415
  145.       TabIndex        =   1
  146.       Top             =   120
  147.       Width           =   1305
  148.    End
  149.    Begin VB.CommandButton FindButton 
  150.       Caption         =   "Find"
  151.       Default         =   -1  'True
  152.       BeginProperty Font 
  153.          Name            =   "MS Sans Serif"
  154.          Size            =   9.75
  155.          Charset         =   0
  156.          Weight          =   400
  157.          Underline       =   0   'False
  158.          Italic          =   0   'False
  159.          Strikethrough   =   0   'False
  160.       EndProperty
  161.       Height          =   480
  162.       Left            =   4050
  163.       TabIndex        =   0
  164.       Top             =   105
  165.       Width           =   1230
  166.    End
  167.    Begin VB.Label Label2 
  168.       Caption         =   "Replace with"
  169.       BeginProperty Font 
  170.          Name            =   "MS Sans Serif"
  171.          Size            =   9.75
  172.          Charset         =   0
  173.          Weight          =   400
  174.          Underline       =   0   'False
  175.          Italic          =   0   'False
  176.          Strikethrough   =   0   'False
  177.       EndProperty
  178.       Height          =   255
  179.       Left            =   150
  180.       TabIndex        =   10
  181.       Top             =   660
  182.       Width           =   1485
  183.    End
  184.    Begin VB.Label Label1 
  185.       Caption         =   "Find what"
  186.       BeginProperty Font 
  187.          Name            =   "MS Sans Serif"
  188.          Size            =   9.75
  189.          Charset         =   0
  190.          Weight          =   400
  191.          Underline       =   0   'False
  192.          Italic          =   0   'False
  193.          Strikethrough   =   0   'False
  194.       EndProperty
  195.       Height          =   240
  196.       Left            =   150
  197.       TabIndex        =   9
  198.       Top             =   195
  199.       Width           =   1410
  200.    End
  201. Attribute VB_Name = "Form2"
  202. Attribute VB_GlobalNameSpace = False
  203. Attribute VB_Creatable = False
  204. Attribute VB_PredeclaredId = True
  205. Attribute VB_Exposed = False
  206. Option Explicit
  207. Dim Position As Integer
  208. Private Sub FindButton_Click()
  209. Dim FindFlags As Integer
  210.     Position = 0
  211.     FindFlags = Check1.Value * 4 + Check2.Value * 2
  212.     Position = Form1.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
  213.     If Position >= 0 Then
  214.         ReplaceButton.Enabled = True
  215.         ReplaceAllButton.Enabled = True
  216.         Form1.SetFocus
  217.     Else
  218.         MsgBox "String not found"
  219.         ReplaceButton.Enabled = False
  220.         ReplaceAllButton.Enabled = False
  221.     End If
  222. End Sub
  223. Private Sub FindNextButton_Click()
  224. Dim FindFlags
  225. FindFlags = Check1.Value * 4 + Check2.Value * 2
  226. Position = Form1.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
  227. If Position > 0 Then
  228.     Form1.SetFocus
  229.     MsgBox "String not found"
  230.     ReplaceButton.Enabled = False
  231.     ReplaceAllButton.Enabled = False
  232. End If
  233. End Sub
  234. Private Sub Command5_Click()
  235.     Form2.Hide
  236. End Sub
  237. Private Sub ReplaceButton_Click()
  238. Dim FindFlags As Integer
  239.     Form1.RichTextBox1.SelText = Text2.Text
  240.     FindFlags = Check1.Value * 4 + Check2.Value * 2
  241.     Position = Form1.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
  242.     If Position > 0 Then
  243.         Form1.SetFocus
  244.     Else
  245.         MsgBox "String not found"
  246.         ReplaceButton.Enabled = False
  247.         ReplaceAllButton.Enabled = False
  248.     End If
  249. End Sub
  250. Private Sub ReplaceAllButton_Click()
  251. Dim FindFlags As Integer
  252.     FindFlags = Check1.Value * 4 + Check2.Value * 2
  253.     Form1.RichTextBox1.SelText = Text2.Text
  254.     Position = Form1.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
  255.     While Position > 0
  256.         Form1.RichTextBox1.SelText = Text2.Text
  257.         Position = Form1.RichTextBox1.Find(Text1.Text, Position + 1, , FindFlags)
  258.     Wend
  259.         ReplaceButton.Enabled = False
  260.         ReplaceAllButton.Enabled = False
  261.         MsgBox "Done replacing"
  262. End Sub
  263.