Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents txtSource As System.Windows.Forms.TextBox
    Friend WithEvents txtSearchFor As System.Windows.Forms.TextBox
    Friend WithEvents txtReplaceWith As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents txtTarget As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.txtSource = New System.Windows.Forms.TextBox()
        Me.txtSearchFor = New System.Windows.Forms.TextBox()
        Me.txtReplaceWith = New System.Windows.Forms.TextBox()
        Me.txtTarget = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(96, 184)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "OK"
        '
        'txtSource
        '
        Me.txtSource.Location = New System.Drawing.Point(120, 32)
        Me.txtSource.Name = "txtSource"
        Me.txtSource.TabIndex = 1
        Me.txtSource.Text = ""
        '
        'txtSearchFor
        '
        Me.txtSearchFor.Location = New System.Drawing.Point(120, 64)
        Me.txtSearchFor.MaxLength = 1
        Me.txtSearchFor.Name = "txtSearchFor"
        Me.txtSearchFor.TabIndex = 2
        Me.txtSearchFor.Text = ""
        '
        'txtReplaceWith
        '
        Me.txtReplaceWith.Location = New System.Drawing.Point(120, 96)
        Me.txtReplaceWith.MaxLength = 1
        Me.txtReplaceWith.Name = "txtReplaceWith"
        Me.txtReplaceWith.TabIndex = 3
        Me.txtReplaceWith.Text = ""
        '
        'txtTarget
        '
        Me.txtTarget.Location = New System.Drawing.Point(120, 128)
        Me.txtTarget.Name = "txtTarget"
        Me.txtTarget.TabIndex = 4
        Me.txtTarget.Text = ""
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(24, 32)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(80, 23)
        Me.Label1.TabIndex = 5
        Me.Label1.Text = "Source:"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(24, 64)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(80, 23)
        Me.Label2.TabIndex = 6
        Me.Label2.Text = "Search For:"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(24, 96)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(80, 23)
        Me.Label3.TabIndex = 7
        Me.Label3.Text = "Replace With:"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(24, 128)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(80, 23)
        Me.Label4.TabIndex = 8
        Me.Label4.Text = "Target:"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label4, Me.Label3, Me.Label2, Me.Label1, Me.txtTarget, Me.txtReplaceWith, Me.txtSearchFor, Me.txtSource, Me.Button1})
        Me.Name = "Form1"
        Me.Text = "Search and Replace"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim intLengthOfSource As Integer
        Dim intLengthOfSearchFor As Integer
        Dim intCounter As Integer
        Dim strSource As String
        Dim strSearchFor As String
        Dim strReplaceWith As String
        Dim strPiece As String
        Dim strTarget As String

        If txtSource.Text = "" Then
            MsgBox("A String to be searched must be entered")
            txtSource.Focus()
            Exit Sub
        ElseIf txtSearchFor.Text = "" Then
            MsgBox("A search character must be entered")
            txtSearchFor.Focus()
            Exit Sub
        ElseIf txtReplaceWith.Text = "" Then
            MsgBox("A replacement character must be entered")
            txtReplaceWith.Focus()
            Exit Sub
        End If

        strSource = txtSource.Text
        strSearchFor = txtSearchFor.Text
        strtarget = txtSource.Text
        strReplaceWith = txtReplaceWith.Text
        intLengthOfSource = Len(strSource)
        intLengthOfSearchFor = Len(strSearchFor)

        For intCounter = 1 To intLengthOfSource Step intLengthOfSearchFor
            strPiece = Mid(strSource, intCounter, intLengthOfSearchFor)
            If strPiece = strSearchFor Then
                Mid(strtarget, intCounter, intLengthOfSearchFor) _
                = strReplaceWith
            End If
        Next intCounter

        txtTarget.Text = strtarget
    End Sub
End Class
