Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

:( 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

Posted (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 by wz2jrz

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...