Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find/Replace process

Status
Not open for further replies.

Squadcar7

IS-IT--Management
Mar 27, 2002
25
US
Hi everyone. Got a quick question. I'd like to have a form that allows you to open a .txt file, find a user specified word in that test file, and then replace it with a user specified string. How would I go about sending the process of Finding the word and then how would I replace it? Any help would be awesome.
 
to get you started...

Code:
Private Sub mnuReplace_Click()
  Static sSearch As String
  Static sReplace As String
  Dim nWhere As Long
  Dim nReply As VbMsgBoxResult
  
  sSearch = InputBox$("Find what", , sSearch)
  
  If sSearch = "" Then Exit Sub
  
  sReplace = InputBox$("Replace with", , sReplace)
  
  If StrPtr(sReplace) = 0 Then Exit Sub ' if user chose 'Cancel'
  
  nWhere = InStr(1, Text1.Text, sSearch)
  
  Do While nWhere
    Text1.SelStart = nWhere - 1
    Text1.SelLength = Len(sSearch)
    nReply = MsgBox("Replace?", vbQuestion + vbYesNoCancel)
    Select Case nReply
      Case vbYes
        Text1.SelText = sReplace
      Case vbNo
        ' pass
      Case vbCancel
        Exit Do
    End Select
    nWhere = InStr(nWhere + 1, Text1.Text, sSearch)
  Loop
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top