Version Compatibility: Visual Basic 5, Visual Basic 6
More information: This function provides the functionality of the VB 6 Split statement for programmers using VB 5.
Instructions: Copy the declarations and code below and paste directly into your VB project.
Public Function Split(ByVal Sin As String, sOut() As String, _
Optional sDelim As String, Optional nLimit As Long = -1, _
Optional bCompare As VbCompareMethod = vbBinaryCompare) As _
Variant
' #VBIDEUtils#*************************************************
' * Programmer Name : Waty Thierry
' * Web Site :
' *www.geocities.com/ResearchTriangle/6311/
' * E-Mail : waty.thierry@usa.net
' * Date : 25/11/98
' * Time : 12:06
' * Module Name : clsIndent
' * Module Filename : Indent.cls
' * Procedure Name : Split
' * Parameters :
' * ByVal sIn As String
' * sOut() As String
' * Optional sDelim As String
' * Optional nLimit As Long = -1
' * Optional bCompare As VbCompareMethod = vbBinaryCompare
' ***********************************************************
' * Comments : Split a string into a variant array
' * This is the equivalent of the VB6 function
' * There are two ways to get the result:
' * 1) Read the sout() array, since it's passed in by Reference
' * 2) Read the return value
' * If no delimiter is provided, the default of " " is used,
' * just like in VB6
' * If the input string does not contain the delimiter,
' * an array with one element -- the input string --
' * is returned, just like in VB6
' **************************************************************
Dim sRead As String, nC As Integer
If sDelim = "" Then sDelim = " "
If InStr(Sin, sDelim) = 0 Then
ReDim sOut(0) As String
sOut(0) = Sin
Split = sOut
Exit Function
End If
sRead = ReadUntil(Sin, sDelim, bCompare)
Do
ReDim Preserve sOut(nC)
sOut(nC) = sRead
nC = nC + 1
If nLimit <> -1 And nC >= nLimit Then Exit Do
sRead = ReadUntil(Sin, sDelim)
Loop While sRead <> "~TWA"
ReDim Preserve sOut(nC)
sOut(nC) = Sin
Split = sOut
End Function
Private Function ReadUntil(ByRef Sin As String, sDelim As _
String, Optional bCompare As VbCompareMethod = _
vbBinaryCompare) As String
' #VBIDEUtils#************************************************
' * Programmer Name : Waty Thierry
' * Web Site : www.geocities.com/ResearchTriangle/6311/
' * E-Mail : waty.thierry@usa.net
' * Date : 25/11/98
' * Time : 12:07
' * Module Name : clsIndent
' * Module Filename : Indent.cls
' * Procedure Name : ReadUntil
' * Parameters :
' * ByRef sIn As String
' * sDelim As String
' * Optional bCompare As VbCompareMethod = vbBinaryCompare
' **************************************************************
' * Comments : Used by the Split function
' *
' *
' *************************************************************
Dim nPos As Long
nPos = InStr(1, Sin, sDelim, bCompare)
If nPos > 0 Then
ReadUntil = Left(Sin, nPos - 1)
Sin = Mid(Sin, nPos + Len(sDelim))
Else
ReadUntil = "~TWA"
End If
End Function
0 comments:
Post a Comment