wz2jrz Posted April 29, 2003 Posted April 29, 2003 :( How can one select a line in Richtextbox and then search of string in it? I have rtb that loads a code file having functions and subs.. i am trying to search for keyword 'function' ignoring the comment lines. i am using find method but it returns that keyword in commented lines too. If i can go line by line then i can look whether the current line is comment or not using instr function.. dont know how to navigate line by line... if someone can write a piece of code that does that- it would be great!! thanks in advance Quote
wz2jrz Posted May 1, 2003 Author Posted May 1, 2003 (edited) Using lines propery of rtb, i found a way to navigate thru all lines using lines array. but i am not able to select the string that i am looking for. string is found in say line 573, but how can i select just that string? rtb.select(??, len(string) .. dont know how to set the startpos in select property. i add length of each lines to get the start but unfortunately it doesnt return the correct . divil, can you help me?:( ---------------heres my function---------------------- Function locate_string2(ByVal search_string As String) As Boolean Dim counter As Integer Dim temparray() As String Dim comment_start As Boolean Dim tot_char As Integer temparray = RichTextBox1.Lines For counter = 0 To temparray.GetUpperBound(0) If InStr(temparray(counter), "/*") > 0 Then comment_start = True GoTo nextfind End If If InStr(temparray(counter), search_string) > 0 Then MsgBox("foundit") End If If InStr(temparray(counter), "*/") > 0 Then comment_start = False If InStr(temparray(counter), search_string) > 0 And comment_start = False Then If InStr(temparray(counter), "//") > 0 Then 'comments line If InStr(temparray(counter), "//") < InStr(temparray(counter), search_string) Then GoTo nextfind End If ElseIf InStr(temparray(counter), "/*") > 0 Then 'comments line If InStr(temparray(counter), "/*") < InStr(temparray(counter), search_string) Then GoTo nextfind End If Else If Trim(temparray(counter)) <> "" Then RichTextBox1.HideSelection = False RichTextBox1.Select(tot_char + InStr(temparray(counter), search_string), Len(temparray(counter))) Return True End If End If End If nextfind: tot_char = tot_char + Len(temparray(counter)) Next End Function Edited May 1, 2003 by wz2jrz Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.