We help IT Professionals succeed at work.

Get string between two strings in memo field

Is there a way to take a function like the one below and have it function on a memo field?


Public Function GetBetween(ByRef sSearch As memo, ByRef sStart As String, ByRef sStop As String, _
                                                    Optional ByRef lSearch As Long = 1) As String
    lSearch = InStr(lSearch, sSearch, sStart)
    If lSearch > 0 Then
        lSearch = lSearch + Len(sStart)
        Dim lTemp As Long
        lTemp = InStr(lSearch, sSearch, sStop)
        If lTemp > lSearch Then
            GetBetween = Mid$(sSearch, lSearch, lTemp - lSearch)
        End If
    End If
End Function
Comment
Watch Question

Commented:
i have tried this with a textbox


Public Function GetBetween(ByRef sSearch As Object, ByRef sStart As String, ByRef sStop As String, _
                                                    Optional ByRef lSearch As Long = 1) As String
    lSearch = InStr(lSearch, sSearch.Text, sStart)
    If lSearch > 0 Then
        lSearch = lSearch + Len(sStart)
        Dim lTemp As Long
        lTemp = InStr(lSearch, sSearch.Text, sStop)
        If lTemp > lSearch Then
            GetBetween = Mid$(sSearch.Text, lSearch, lTemp - lSearch)
        End If
    End If
End Function

Commented:
note that the difference is that i used the text property of the object, and not the object itself
Retired IT Professional
Commented:
Try:
 Public Function GetBetween(ByRef sSearch As String, ByRef sStart As String, ByRef sStop As String, _
                                                    Optional ByRef lSearch As Long = 1) As String
        'parameter ByRef sSearch As String,                modified ---------

        lSearch = InStr(sSearch, sStart)      'modified --------------------
        GetBetween = ""                             'added -----------------------
        If lSearch > 0 Then
            lSearch = lSearch + Len(sStart)
            Dim lTemp As Long
            lTemp = InStr(sSearch, sStop)     'modified --------------------
            If lTemp > lSearch Then
                GetBetween = Mid$(sSearch, lSearch, lTemp - lSearch)
            End If
        End If
    End Function