Thursday, June 18, 2009

Find String

Possible friends some of not yet known, to do find of string at one particular or sentence of text long. To easy to find of string, follow steps hereunder:

  • First, create a new module first. Give the name "mdlfindstring" or it's friends.
  • Then enter the code below to the module.

    Public Function FindString(ByVal Text As String, _
    ByVal Search As String, _
    Optional ByVal Position As Long, _
    Optional CaseSensitive As Boolean, _
    Optional ByVal Up As Boolean) _
    As Long

    Dim lPos As Long
    Dim lFind As Long

    If Text <> "" Then
    If Position < 1 Then Position = 1
    If Position > Len(Text) Then Position = Len(Text)
    If Up Then
    lPos = Position - 1
    While lPos > 0
    lFind = InStr(lPos, Text, Search, Abs(Not CaseSensitive))
    If lFind = lPos Then
    lPos = 0
    Else
    lFind = 0
    lPos = lPos - 1
    End If
    Wend
    FindString = lFind
    Else
    FindString = InStr(Position + 1, Text, Search, _
    Abs(Not CaseSensitive))
    End If
    End If
    End Function


1 comment: