473,473 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need line of found text in RichTextBox

5 New Member
Hi,

if anyone can help me . i am displaying a textfile in a richTextBox. then i am implementing the search functionality. i need a code that would return for me the number of the line the search was found / or the index of the line( where in my file what i want to search for wasfound )
Aug 3 '07 #1
2 1143
Killer42
8,435 Recognized Expert Expert
I think you'll get what you want by combining GetLineFromChar method with the SelStart property.
Aug 3 '07 #2
debasisdas
8,127 Recognized Expert Expert
Try this following sample code. It directly reads from the file not through a rich textbox, you may modify as required.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim n As String
  3. Dim ctr As Integer
  4. Dim CTR1 As Integer
  5. Dim STR As String
  6. Dim i As Integer
  7. Dim LNCOUNT As Integer
  8. Dim LNWORDCOUNT As Integer
  9. List1.Clear
  10. Label1.Caption = ""
  11. On Error GoTo err1
  12. cd.DialogTitle = "Open File"
  13. cd.InitDir = "d:\"
  14. cd.CancelError = True
  15. cd.ShowOpen
  16. T2 = Trim(Text1.Text)
  17. Open cd.FileName For Input As #1
  18. Do Until EOF(1)
  19.   Line Input #1, n
  20.   LNWORDCOUNT = 0
  21.   LNCOUNT = LNCOUNT + 1
  22.   T1 = n
  23.   CT = 1
  24.   Do While CT <= Len(T1)
  25.     ctr = InStr(CT, T1, T2)
  26.     If ctr <> 0 Then
  27.       CT = ctr + 1
  28.       CTR1 = CTR1 + 1
  29.       LNWORDCOUNT = LNWORDCOUNT + 1
  30.     Else
  31.       Exit Do
  32.     End If
  33.   Loop
  34.   'Print LNCOUNT & "    " & LNWORDCOUNT
  35.   If LNWORDCOUNT <> 0 Then
  36.     List1.AddItem "Line No :" & LNCOUNT & "    " & "Occurrence :" & LNWORDCOUNT
  37.   End If
  38. Loop
  39. Label1.Caption = "Total Occurrences In File : " & CTR1
  40. Close #1
  41. Exit Sub
  42. err1:
  43. MsgBox Err.Description
  44. End Sub
Hope that solves your problem.
Aug 3 '07 #3

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

Similar topics

3
by: kangoo | last post by:
Hi, I'm trying to remove the last charater in a richTextBox. I though richTextBox.Text.Remove(richTextBox.Text.length-1, 1); would work, but it does nothing (eg richTextBox.Text += "some new...
2
by: Martin Dew | last post by:
I have a RichTextBox called rtbOutput. I am adding lines of text using the AppendText method. What I want to do is immediately after adding this line of text make sure that this line of text is...
3
by: Rvo | last post by:
I have a userform which contains a textbox (System.Windows.forms.textbox) with multiline set to True. This box contains a certain number of characters which reach below the bottom of the box....
2
by: Just Me | last post by:
I insert text in a RichTextBox ending each line with vbCrLf. I think when I search the RichTextBox text I do not find any CR's. In the Text property is the end of line char a LineFeed? Are...
2
by: RobKinney1 | last post by:
Hello and thank you for reading this post. I have a RichTextBox. I need to select text inside for a search feature. Easy enough... right? Well apparently from the .NET help and everything from...
20
by: Jason | last post by:
Hello For a VB novice can anyone help me with the following simple idea. All I've got on my form is a Textbox, (mulitline = true) and a button. When I click the button I will have some...
4
by: Franky | last post by:
What I want to do is delete the last line in a RichTextBox. The RichTextBox has a ReadOnly property called lines that seems like it might help but I cant figure out how to use it. Well, the...
2
by: aemihal | last post by:
Hello, I have a RichTextBox that has a large number of lines, well in excess of the amount that can be seen without scrolling. Upon an event, such as clicking a button, I would like to move the...
0
by: Vimalathithan | last post by:
I just developing a editor. I have provide the options like Bold, Italic, underlin, font change, font size change. These font options are keep in with one toolstripbutton. the toolstripbar keep...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.