Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Help me plz

Name: Anonymous 2009-05-18 0:49

I need some help doing this Visual Basic project.... I need to incorporate into my Notepad-like program a find/replace function. I already have the Replace all working fine, but I can't figure out how to make my find button a find + find next (ex. it finds one occurrence, you press it again and the next occurrence is highlighted) Here is what i gots so far.

a = txtSearchWord.Text

b = InStr(TextEditor.txtMain.Text, txtSearchWord.Text)

If b Then

TextEditor.txtMain.Focus()

TextEditor.txtMain.SelectionStart = b - 1

TextEditor.txtMain.SelectionLength = Len(a)

Else

MsgBox("Text not found.")

End If

Name: Anonymous 2009-05-18 2:05

>>11
Make a function that takes a position as parameter:

Private Sub Find(ByVal startPosition as integer)

That's so you can keep track of where you are in the text if you've done more than one Find (i.e. to do find next). The first time, send either 0 or 1 as the position (start). Inside the class, also declare one integer that will contain the position of your result (here, targetPosition) and one string that will actually contain the string (here, target).

Declare another position integer inside the function.
Dim position as Integer

position = InStr(startPosition, TextEditor.txtMain.Text, txtSearchWord.Text)


If to check whether or not you have a result,

If position > 0 Then
targetPosition = position


Close to what you were doing, you should get this part without explanations

TextEditor.txtMain.SelectionStart = targetPosition
TextEditor.txtMain.SelectionLength = Len(target) - (Len(target) - Len(target))


Finish the if

Else
MsgBox("Text Not Found")
target = ""
End If

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List