?
Solved

Searching and replacing words from a text box

Posted on 2003-03-17
10
Medium Priority
?
191 Views
Last Modified: 2010-05-03
If i have a textbox with some text in it, how cand i search and replace a word let's say "word" with some other words "word number 2".
0
Comment
Question by:macaila
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 150 total points
ID: 8154736
textbox1.text = Replace(textbox1.text, "word", "word number 2")
0
 

Expert Comment

by:kidgenius2002
ID: 8154749
if you know what the word is, and it's length, you could do something like the following

x=1
'z is length of "word", in this case 4'
z= 4
do until mid(textbox1.text,x,z) = "word"
     x=1+x
     loop
textbox1.text = left(textbox1.text,x) & "word number 2" & right(textbox1.ext,x+z)
0
 
LVL 3

Expert Comment

by:DocM
ID: 8154790
Or the old method:

a = "1234 word 5678"
 strToSearch = "word"
 strReplaceBy = "word number 2"
 start = 1
While InStr(start, a, strToSearch)
 a = Mid(a, 1, InStr(start, a, strToSearch) - 1) & strReplaceBy & Mid(a, InStr(start, a, strToSearch) + Len(strToSearch))
 start = start + Len(strReplaceBy)
Wend
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:Jacamar
ID: 8154797
Here you go.

Private Sub Command1_Click()
Text1.Text = Replace(Text1.Text, "word", _
                "word number 2")

Text1.Text = Replace(Text1.Text, "word", _
                "word")

Text1.SelStart = Len(Text1.Text)

End Sub
0
 
LVL 14

Expert Comment

by:aelatik
ID: 8154999
OK, i think im missing something here ! What is wrong with bobbit31's post. It's the best answer that fits this question, why make it so complex ?
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8155085
lol, my thoughts exactly ;)
0
 
LVL 3

Expert Comment

by:DocM
ID: 8155355
Some like it complex.
And it is only with an educational purpose.
0
 

Author Comment

by:macaila
ID: 8158621
I'll accept one answer as soon as I get VB6 I use VB4 so I get error messages.
0
 

Author Comment

by:macaila
ID: 8173943
Well bobbit31 was the first person who answered me and i try not to make my programs complex because that would mean they wouldn't run on older computers...
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8174308
so why the 'B' grade?
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question