Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.



Public Function lngEndString(strIn As String, ByVal lngStart As Long, strChars As String, lngInc As Long)
' Procedure :   lngEndString
' Description:  Calculates the left-most or right-most end of a sub-string.
' Copyright: Chris Greaves Inc.
' Inputs:       String, possible empty, to be searched up to 2G (32 bit) in length.
'               Starting index within that string.
'               String, possibly empty, of allowable characters within the substring (stop scan when not valid).
'               Increment -1==> look towards the left, +1==> towards the right.
' Returns:      A pointer to one end of a sub-string of the original string
' Assumes:      Nothing
' Side Effects: If either string is null, the result will be the original value of the Starting index.
' Tested:       By the calls shown below.
Dim bool As Boolean
bool = (lngStart > 0) And (lngStart < Len(strIn))
lngEndString = lngStart
If lngInc < 0 Then
    Do While bool
        lngStart = lngStart + lngInc
        bool = lngStart > 0
        If bool Then bool = (InStr(1, strChars, Mid(strIn, lngStart, 1)) > 0)
        lngEndString = lngStart - lngInc
    Loop
Else
    If lngInc > 0 Then
        Do While bool
            lngStart = lngStart + lngInc
            bool = lngStart <= Len(strIn)
            If bool Then bool = (InStr(1, strChars, Mid(strIn, lngStart, 1)) > 0)
            lngEndString = lngStart - lngInc
        Loop
    Else
    End If
End If
'Sub TESTlngEndString()
'MsgBox lngEndString("a message for [email protected] of Toronto", 23, ".abcdefghihjklmnopqrstuvwxyz", -1)
'MsgBox lngEndString("a message for [email protected] of Toronto", 23, ".abcdefghihjklmnopqrstuvwxyz", 1)
'MsgBox Mid("a message for [email protected] of Toronto", 15, 35 - 15 + 1)
'MsgBox lngEndString("c@g", 2, "abcdefghihjklmnopqrstuvwxyz", -1)
'MsgBox lngEndString("c@g", 2, "abcdefghihjklmnopqrstuvwxyz", 1)
'MsgBox lngEndString("", 2, "abcdefghihjklmnopqrstuvwxyz", -1)
'MsgBox lngEndString("", 2, "abcdefghihjklmnopqrstuvwxyz", 1)
'MsgBox lngEndString("c@g", 2, "", -1)
'MsgBox lngEndString("c@g", 2, "", 1)
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1

Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.

Public Function lngEndString(strIn As String, ByVal lngStart As Long, strChars As String, lngInc As Long)
' Procedure :   lngEndString
' Description:  Calculates the left-most or right-most end of a sub-string.
' Copyright: Chris Greaves Inc.
' Inputs:       String, possible empty, to be searched up to 2G (32 bit) in length.
'               Starting index within that string.
'               String, possibly empty, of allowable characters within the substring (stop scan when not valid).
'               Increment -1==> look towards the left, +1==> towards the right.
' Returns:      A pointer to one end of a sub-string of the original string
' Assumes:      Nothing
' Side Effects: If either string is null, the result will be the original value of the Starting index.
' Tested:       By the calls shown below.
Dim bool As Boolean
bool = (lngStart > 0) And (lngStart < Len(strIn))
lngEndString = lngStart
If lngInc < 0 Then
    Do While bool
        lngStart = lngStart + lngInc
        bool = lngStart > 0
        If bool Then bool = (InStr(1, strChars, Mid(strIn, lngStart, 1)) > 0)
        lngEndString = lngStart - lngInc
    Loop
Else
    If lngInc > 0 Then
        Do While bool
            lngStart = lngStart + lngInc
            bool = lngStart <= Len(strIn)
            If bool Then bool = (InStr(1, strChars, Mid(strIn, lngStart, 1)) > 0)
            lngEndString = lngStart - lngInc
        Loop
    Else
    End If
End If
'Sub TESTlngEndString()
'MsgBox lngEndString("a message for [email protected] of Toronto", 23, ".abcdefghihjklmnopqrstuvwxyz", -1)
'MsgBox lngEndString("a message for [email protected] of Toronto", 23, ".abcdefghihjklmnopqrstuvwxyz", 1)
'MsgBox Mid("a message for [email protected] of Toronto", 15, 35 - 15 + 1)
'MsgBox lngEndString("c@g", 2, "abcdefghihjklmnopqrstuvwxyz", -1)
'MsgBox lngEndString("c@g", 2, "abcdefghihjklmnopqrstuvwxyz", 1)
'MsgBox lngEndString("", 2, "abcdefghihjklmnopqrstuvwxyz", -1)
'MsgBox lngEndString("", 2, "abcdefghihjklmnopqrstuvwxyz", 1)
'MsgBox lngEndString("c@g", 2, "", -1)
'MsgBox lngEndString("c@g", 2, "", 1)
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1