Source code for Issue Number 55

Copyright 1997-2000 by C&D Programming Corp. All Rights Reserved. Source code may not be reproduced except for use in a compiled executable. All rights reserved. If you would like to reprint any or all of this code please email us at info@codeoftheweek.com

Code of the Week Home


Source Code

Just paste this source code into a module called basStrings and include it in your project.

'----------------------------------------------------------------------
'
'   Module Name:    basStrings
'   Written By:     C&D Programming Corp.
'   Create Date:    8/98
'   Copyright:      Copyright 1998 by C&D Programming Corp.  Source
'                   code may not be reproduced except for use in a
'                   compiled executable.  All rights reserved.  If
'                   you would like to reprint any or all of this
'                   code please email us at info@codeoftheweek.com
'----------------------------------------------------------------------
Option Explicit

Public Function FindLastOccurrence(sData As String, sSearchString As String) As Long

    Dim lPos As Long
    Dim lLastPos As Long

    On Error Goto Handler
    lPos = 0
    Do
        lLastPos = lPos
        lPos = InStr(lPos + 1, sData, sSearchString, vbBinaryCompare)
        If lPos = 0 Then Exit Do
    Loop
    FindLastOccurrence = lLastPos
    Exit Function

Handler:
    Err.Raise Err.Number, "FindLastOccurrence", Err.Description
End Function