home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch05 / textpad / search.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-03-07  |  8.6 KB  |  273 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.CheckBox Check1 
  13.       Caption         =   "Case sensitive"
  14.       BeginProperty Font 
  15.          Name            =   "MS Sans Serif"
  16.          Size            =   9.75
  17.          Charset         =   0
  18.          Weight          =   400
  19.          Underline       =   0   'False
  20.          Italic          =   0   'False
  21.          Strikethrough   =   0   'False
  22.       EndProperty
  23.       Height          =   240
  24.       Left            =   90
  25.       TabIndex        =   9
  26.       Top             =   1260
  27.       Width           =   2040
  28.    End
  29.    Begin VB.CommandButton Command5 
  30.       Cancel          =   -1  'True
  31.       Caption         =   "CLOSE"
  32.       BeginProperty Font 
  33.          Name            =   "MS Sans Serif"
  34.          Size            =   9.75
  35.          Charset         =   0
  36.          Weight          =   400
  37.          Underline       =   0   'False
  38.          Italic          =   0   'False
  39.          Strikethrough   =   0   'False
  40.       EndProperty
  41.       Height          =   480
  42.       Left            =   5460
  43.       TabIndex        =   8
  44.       Top             =   1335
  45.       Width           =   1245
  46.    End
  47.    Begin VB.CommandButton ReplaceAllButton 
  48.       Caption         =   "Replace All"
  49.       Enabled         =   0   'False
  50.       BeginProperty Font 
  51.          Name            =   "MS Sans Serif"
  52.          Size            =   9.75
  53.          Charset         =   0
  54.          Weight          =   400
  55.          Underline       =   0   'False
  56.          Italic          =   0   'False
  57.          Strikethrough   =   0   'False
  58.       EndProperty
  59.       Height          =   480
  60.       Left            =   5430
  61.       TabIndex        =   7
  62.       Top             =   630
  63.       Width           =   1275
  64.    End
  65.    Begin VB.CommandButton ReplaceButton 
  66.       Caption         =   "Replace"
  67.       Enabled         =   0   'False
  68.       BeginProperty Font 
  69.          Name            =   "MS Sans Serif"
  70.          Size            =   9.75
  71.          Charset         =   0
  72.          Weight          =   400
  73.          Underline       =   0   'False
  74.          Italic          =   0   'False
  75.          Strikethrough   =   0   'False
  76.       EndProperty
  77.       Height          =   480
  78.       Left            =   4065
  79.       TabIndex        =   6
  80.       Top             =   600
  81.       Width           =   1215
  82.    End
  83.    Begin VB.CommandButton FindNextButton 
  84.       Caption         =   "Find Again"
  85.       BeginProperty Font 
  86.          Name            =   "MS Sans Serif"
  87.          Size            =   9.75
  88.          Charset         =   0
  89.          Weight          =   400
  90.          Underline       =   0   'False
  91.          Italic          =   0   'False
  92.          Strikethrough   =   0   'False
  93.       EndProperty
  94.       Height          =   480
  95.       Left            =   5415
  96.       TabIndex        =   5
  97.       Top             =   120
  98.       Width           =   1305
  99.    End
  100.    Begin VB.CommandButton FindButton 
  101.       Caption         =   "Find"
  102.       Default         =   -1  'True
  103.       BeginProperty Font 
  104.          Name            =   "MS Sans Serif"
  105.          Size            =   9.75
  106.          Charset         =   0
  107.          Weight          =   400
  108.          Underline       =   0   'False
  109.          Italic          =   0   'False
  110.          Strikethrough   =   0   'False
  111.       EndProperty
  112.       Height          =   480
  113.       Left            =   4050
  114.       TabIndex        =   4
  115.       Top             =   105
  116.       Width           =   1230
  117.    End
  118.    Begin VB.TextBox Text1 
  119.       BeginProperty Font 
  120.          Name            =   "MS Sans Serif"
  121.          Size            =   9.75
  122.          Charset         =   0
  123.          Weight          =   400
  124.          Underline       =   0   'False
  125.          Italic          =   0   'False
  126.          Strikethrough   =   0   'False
  127.       EndProperty
  128.       Height          =   285
  129.       Left            =   1500
  130.       TabIndex        =   1
  131.       Top             =   105
  132.       Width           =   2115
  133.    End
  134.    Begin VB.TextBox Text2 
  135.       BeginProperty Font 
  136.          Name            =   "MS Sans Serif"
  137.          Size            =   9.75
  138.          Charset         =   0
  139.          Weight          =   400
  140.          Underline       =   0   'False
  141.          Italic          =   0   'False
  142.          Strikethrough   =   0   'False
  143.       EndProperty
  144.       Height          =   285
  145.       Left            =   1485
  146.       TabIndex        =   3
  147.       Top             =   510
  148.       Width           =   2130
  149.    End
  150.    Begin VB.Label Label2 
  151.       Caption         =   "Replace with"
  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          =   255
  162.       Left            =   60
  163.       TabIndex        =   0
  164.       Top             =   540
  165.       Width           =   1290
  166.    End
  167.    Begin VB.Label Label1 
  168.       Caption         =   "Find What"
  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          =   240
  179.       Left            =   75
  180.       TabIndex        =   2
  181.       Top             =   135
  182.       Width           =   1320
  183.    End
  184. Attribute VB_Name = "Form2"
  185. Attribute VB_GlobalNameSpace = False
  186. Attribute VB_Creatable = False
  187. Attribute VB_PredeclaredId = True
  188. Attribute VB_Exposed = False
  189. Option Explicit
  190. Dim Position As Integer
  191. Private Sub FindButton_Click()
  192. Dim compare As Integer
  193. Position = 0
  194. If Check1.Value = 1 Then
  195.     compare = vbBinaryCompare
  196.     compare = vbTextCompare
  197. End If
  198. Position = InStr(Position + 1, Form1.Editor.Text, Text1.Text, compare)
  199. If Position > 0 Then
  200.     ReplaceButton.Enabled = True
  201.     ReplaceAllButton.Enabled = True
  202.     Form1.Editor.SelStart = Position - 1
  203.     Form1.Editor.SelLength = Len(Text1.Text)
  204.     Form1.SetFocus
  205.     MsgBox "String not found"
  206.     ReplaceButton.Enabled = False
  207.     ReplaceAllButton.Enabled = False
  208. End If
  209. End Sub
  210. Private Sub FindNextButton_Click()
  211. Dim compare As Integer
  212. If Check1.Value = 1 Then
  213.     compare = vbBinaryCompare
  214.     compare = vbTextCompare
  215. End If
  216. Position = InStr(Position + 1, Form1.Editor.Text, Text1.Text, compare)
  217. If Position > 0 Then
  218.     Form1.Editor.SelStart = Position - 1
  219.     Form1.Editor.SelLength = Len(Text1.Text)
  220.     Form1.SetFocus
  221.     MsgBox "String not found"
  222.     ReplaceButton.Enabled = False
  223.     ReplaceAllButton.Enabled = False
  224. End If
  225. End Sub
  226. Private Sub Command5_Click()
  227.     Form2.Hide
  228. End Sub
  229. Private Sub Form_Load()
  230. Dim ret As Long
  231.     Me.Show
  232.     ret = SetWindowPos(Me.hwnd, HWND_TOPMOST, Me.CurrentX, Me.CurrentY, Me.Width, Me.Height, SWP_SHOWWINDOW Or SWP_NOSIZE Or SWP_NOMOVE)
  233. End Sub
  234. Private Sub ReplaceButton_Click()
  235. Dim compare As Integer
  236.     Form1.Editor.SelText = Text2.Text
  237.     If Check1.Value = 1 Then
  238.         compare = vbBinaryCompare
  239.     Else
  240.         compare = vbTextCompare
  241.     End If
  242.     Position = InStr(Position + 1, Form1.Editor.Text, Text1.Text, compare)
  243.     If Position > 0 Then
  244.         Form1.Editor.SelStart = Position - 1
  245.         Form1.Editor.SelLength = Len(Text1.Text)
  246.         Form1.SetFocus
  247.     Else
  248.         MsgBox "String not found"
  249.         ReplaceButton.Enabled = False
  250.         ReplaceAllButton.Enabled = False
  251.     End If
  252. End Sub
  253. Private Sub ReplaceAllButton_Click()
  254. Dim compare As Integer
  255.     Form1.Editor.SelText = Text2.Text
  256.     If Check1.Value = 1 Then
  257.         compare = vbBinaryCompare
  258.     Else
  259.         compare = vbTextCompare
  260.     End If
  261.     Position = InStr(Position + 1, Form1.Editor.Text, Text1.Text, compare)
  262.     While Position > 0
  263.         Form1.Editor.SelStart = Position - 1
  264.         Form1.Editor.SelLength = Len(Text1.Text)
  265.         Form1.Editor.SelText = Text2.Text
  266.         Position = Position + Len(Text2.Text)
  267.         Position = InStr(Position + 1, Form1.Editor.Text, Text1.Text)
  268.     Wend
  269.         ReplaceButton.Enabled = False
  270.         ReplaceAllButton.Enabled = False
  271.         MsgBox "Done replacing"
  272. End Sub
  273.