No Split Function

cable

Access For My Sins
Local time
Today, 20:40
Joined
Mar 11, 2002
Messages
228
For some reason I don't have the split function...has any one got some nice fast code to achive the same result?
 
Is it due to a missing reference or the use of A97 that you don't have the Split() function?
 
Mile-O-Phile said:
Is it due to a missing reference or the use of A97 that you don't have the Split() function?
Using A97...If HP get their act together we will be changing to xp and office 2003, but not any time soon.
 
If the problem is that you're using A97 (which has no Split() function), here's a potential work-around:
Code:
Function ySplit(ByVal pTarget As String, _
                pItem As String, _
                Optional ShowLeft As Boolean = True) _
                As String
'*******************************************
'Purpose:    Splits a string to the left or
'            right of pItem
'Coded by:   raskew
'Inputs:     1)  ySplit("The quick+ brown fox", "+", True)
'            2)  ysplit("The quick+ brown fox", "+", False)
'Output:     1)  The quick
'            2)  brown fox
'*******************************************

Dim strLeft  As String
Dim strRight As String
Dim n        As Integer

    n = InStr(pTarget, pItem)
    
    If n = 0 Then
       ySplit = pTarget
    Else
       ShowLeft = IIf(IsMissing(ShowLeft), True, ShowLeft)
       strLeft = Left(pTarget, n - 1)
       strRight = Mid(pTarget, n + 1)
       ySplit = IIf(ShowLeft, strLeft, strRight)
    End If
    
End Function
HTH - Bob
 
Thats a start, but I'm going to have a unknown number of returns, so it would have to return an array.
 
Code:
Public Function SplitS(sString As String, sDel As String) As Variant
Dim sLocal() As String
Dim I As Integer
Dim iBnd As Integer

sString = Trim$(sString)

If Right$(sString, 1) <> sDel Then sString = sString & sDel
I = InStr(sString, sDel)

Do Until I = 0
    iBnd = iBnd + 1
    ReDim Preserve sLocal(iBnd)
    sLocal(iBnd - 1) = Trim$(Left$(sString, I - 1))
    sString = Right$(sString, Len(sString) - I)
    I = InStr(sString, sDel)
Loop

ReDim Preserve sLocal(iBnd - 1)
SplitS = sLocal
End Function
That seems a fairly logical way, any problems or any faster methods?
 

Users who are viewing this thread

Back
Top Bottom