Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)
This is a InStrRev function for VB5. I took a look at the one microsoft recomend, and almost died of laughter.
Inputs
The string to Search
The string to Find
Optional :> The start position
Code Returns
The postion of the Found string in the Searched string.
Side Effects
None.
Function myInStrRev(strStringToSearch As String, strFind As String, Optional iStart As Long) As Long
Dim ip1 As Long, ip2 As Long
Dim iLenStringToSearch As Long
'get the length of the string
iLenStringToSearch = Len(strStringToSearch)
'if the start is 0 then set the start to the length
'og the string
If iStart = 0 Then
iStart = iLenStringToSearch
End If
ip1 = 1
Do
ip2 = InStr(ip1, strStringToSearch, strFind)
If (ip2 > 0) And (ip2 < iStart) Then
'if ip2 is not zero and it is less than the
'place to start searching then set the function
'to return that position
myInStrRev = ip2
ElseIf ip2 = 0 Then
ip2 = iLenStringToSearch
End If
'set the next position to seracf from
ip1 = ip2 + 1
Loop Until ip1 >= iStart
End Function