Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Searching and replacing words from a text box

Posted on 2003-03-17
10
Medium Priority
?
192 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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

581 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