i search when the caret is at the startof the text box in teh first line at the start of hte line then [lengthPosition = InStr(varPosition, frmNotepad.txtNotepad.Text, Value, CaseSensative) 'Find Value After Caret varPosition] comes back in error it just highlights the line in yellow and doesnt say what the error is
the other problem i am having is when searching upwards the loops back around and starts form the bottom upwards and i want to stop this form happening
anyone got any suggestions
Public Sub FindNext(ByVal Value, ByVal Direction, ByVal CaseSensative)
If Value IsNot Nothing Then ' Only run if Search String is not Null
' Set The CaseSensative to the appropriate Search Method
If CaseSensative = False Then
CaseSensative = CompareMethod.Text
Else
CaseSensative = CompareMethod.Binary
End If
' Set Search Start Location Based on Selection Length
Dim varPosition As Integer = frmNotepad.txtNotepad.SelectionStart + frmNotepad.txtNotepad.SelectionLength
' Search for the Text In the specified Direction from the text cursor
Dim lengthPosition As Long ' Declare Search Result Variable
If Direction = "Down" Then
lengthPosition = InStr(varPosition, frmNotepad.txtNotepad.Text, Value, CaseSensative) 'Find Value After Caret varPosition
Else
Dim varText As String = ReverseString(frmNotepad.txtNotepad.Text) 'Set varText to txtNotepad Contents
Dim varTextLength As Integer = Len(varText) ' Get the Length of varText
If varPosition > 0 Then ' Attempt to Stop the Search Looping when at Start of Document
lengthPosition = varTextLength - InStr(varTextLength - frmNotepad.txtNotepad.SelectionStart, varText, ReverseString(Value), CaseSensative) - 2 'Reverse Everything to Find Value Before Caret varPosition
End If
End If
' Select Searched Text
If lengthPosition > 0 Then
frmNotepad.txtNotepad.SelectionStart = lengthPosition - 1 ' Move Caret to Start of Text
frmNotepad.txtNotepad.SelectionLength = Len(Value) ' Set Length of Selection to the Search String
Else
MsgBox("Cannot find " + Chr(34) + varFind + Chr(34), MsgBoxStyle.Information) ' Display Message if no more Instances of Search String in Specified Direction or None at all
End If
CaretRefresh(frmNotepad.txtNotepad) ' Scroll txtNotepad to Caret Position
SetCharacterPosition() ' Update Line / Character in Status Bar
End If
End Sub



Help
Back to top








