Function String Searches Class

InStrReverse

"In String Reverse" Find the last occurrence of one string within another. Similar to the Visual Basic InStr function except that it searches backwards from the end of string vLine. Different from the InStr function in that it returns 0 if vFind is an empty string.

Signature (Visual Basic / VBA)

Public Function InStrReverse( _
      ByVal vStartPos As Variant _
    , ByVal vLine As Variant _
    , ByVal vFind As Variant _
    , Optional ByVal vCompare As Variant _
    ) As Variant

Code Example

    InStrReverse(Null, "THIS IS A TEST.", "IS") = 6
    InStrReverse(Null, "THIS IS A TEST.", "SAMPLE") = 0

Parameters

Parameter Description
vLine The string which is to be searched from right-to-left for the appearance of string vFind. Function returns Null if vLine is Null or cannot be fixed up to a String.
vFind The string which is to be searched for within string vLine. Function returns Null if vFind is Null or cannot be fixed up to a String.
vStartPos The character position in string vLine where the search is to begin. vStartPos defaults to the position of the last character in the string vLine (the length of the line) if it is Null or cannot be fixed up to a number. Even though this function is looking for the last match, it searches forward for the string vFind.
vCompare Specifies the type of comparison used to determine if the strings match. vCompare defaults to Binary comparisons if it is missing or Null or cannot be fixed up to a number. Function returns 0 (zero) if string vFind does not appear anywhere within string vLine.

Notes & Version History

Note Function returns the starting position vStartPos if vFind is an empty string.
v1.5 Note This function is similar to the new InStrRev function in Visual Basic 6.0, except that the arguments are arranged differently.