473,395 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Searching a textbox

4
This is my first posting. Can you help me with this, please.
I know how to search for a word in a TextBox control and highlight it when found. Then step through the textbox for any further words.
My problem is how to highlight all the found words at the same time like for instance in the VB Helpfile. I am using VB6. Thank you in advance.
May 23 '07 #1
6 1902
Dököll
2,364 Expert 2GB
This is my first posting. Can you help me with this, please.
I know how to search for a word in a TextBox control and highlight it when found. Then step through the textbox for any further words.
My problem is how to highlight all the found words at the same time like for instance in the VB Helpfile. I am using VB6. Thank you in advance.
Greeitngs, Wout86!

You may be closer than you think. Why don't you add the same command for other words to find. I am not sure what your code looks like, but try telling VB to highlight additional words.

Please post your code if this isn't clear.

Dököll
May 23 '07 #2
Wout86
4
My code is as follows:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private TargetPosition As Integer
  4. ' Find the text.
  5. Private Sub cmdFind_Click()
  6.     FindText 1
  7. End Sub
  8. Private Sub FindText(ByVal start_at As Integer)
  9. Dim pos As Integer
  10. Dim target As String
  11.  
  12.     target = txtTarget.Text
  13.     pos = InStr(start_at, txtBody.Text, target)
  14.     If pos > 0 Then
  15.         ' We found it.
  16.         TargetPosition = pos
  17.         txtBody.SelStart = TargetPosition - 1
  18.         txtBody.SelLength = Len(target)
  19.         txtBody.SetFocus
  20.     Else
  21.         ' We did not find it.
  22.         MsgBox "Not found."
  23.         txtBody.SetFocus
  24.     End If
  25. End Sub
  26.  
  27. ' Find the next occurrance of the text.
  28. Private Sub cmdFindNext_Click()
  29.     FindText TargetPosition + 1
  30.  
  31. End Sub
Thanks for speedy reply!
May 23 '07 #3
Killer42
8,435 Expert 8TB
This is my first posting. Can you help me with this, please.
I know how to search for a word in a TextBox control and highlight it when found. Then step through the textbox for any further words.
My problem is how to highlight all the found words at the same time like for instance in the VB Helpfile. I am using VB6. Thank you in advance.
Hate to be a wet blanket, but I don't think it's possible, at least in a normal textbox. You select part of the text by setting the .SelStart and .SelLength properties. This simple level of control doesn't provide any way to select more than one section. I imagine it might be possible through API calls, but have no idea how.

On the other hand, if you were to use a RichTextBox control, you might be able to achieve what you want. I don't think it can actually select multiple sections at the same time either, but you can select each in turn and set some font format to highlight it, such as the text colour.
May 23 '07 #4
Wout86
4
Oh well, worth a try. I try your suggestion and have a go with a RichTextBox.
Thanks anyway for trying.
May 23 '07 #5
Dököll
2,364 Expert 2GB
Hate to be a wet blanket, but I don't think it's possible...
Wet blanket! It's pouring rain here:-)

How does Google do it, anyway? I think I am going to go Noodle with this one, see what I come up with...
May 24 '07 #6
Killer42
8,435 Expert 8TB
How does Google do it, anyway?
It's easy - they don't use the old Windows TextBox control.

I think I am going to go Noodle with this one, see what I come up with...
Good luck.
May 24 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: donald | last post by:
Hi all, I have a website running asp (about to move to asp.net soon though) which has a list of DVD's I have the various pages I want, last 10, listing, full listing ect, but the one page i can't...
3
by: MoonWa | last post by:
Short of going char by char, how do I search for a pattern in the text for a textbox Thanks MoonWa
5
by: Andy | last post by:
I am having trouble using the ComboBox in my app. I am attempting to use the text from the ComboBox, to search the list box portion. However: In my "TextChanged" event: I cannot get the value...
4
by: libsfan01 | last post by:
Im not entirely sure this involves JS but bear with me... I'm looking to implement a system on a site where the user starts to type in the search box (textbox) what they are looking for and this...
1
by: sivagururaja | last post by:
Hi All, Im using ASP.NET with C#. (.NET 2005) In my page i want to allow the user to search the text from the SQL table. This is my table ID Name City State 1 Parry ...
5
by: tshad | last post by:
Does anyone have or know where I can get a some code that will check a TextBox for inappropriate language. At the moment, we need to manually check submissions for language before posting. This...
2
by: =?Utf-8?B?VGVycnk=?= | last post by:
I am implementing an 'incremental search', where as the user types into a textbox, a datagridview's current position is updated to match the first record that contains what the user has typed so...
8
by: fniles | last post by:
I am using VB.NET 2008. I would like to search a textbox (find next and find previous), and when it finds the text, move my cursor in the textbox to where the found text is. How can I do that ?...
2
by: wietmie | last post by:
Hai, i just wanna ask, is it possible to do a searching result like google using VB6.0, but google are too complicated, what i mean just, user put the searching word in the textbox, then it will...
4
by: aaronkmar | last post by:
Hello Bytes, I hope this post finds you well on this wonderful Friday! I've been kicking this code around for over a week now and cannot seem to find the correct syntax to handle all of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.