Public Function basSplit(StrIn As String, _
Optional DelimChar As String = " ") _
As Variant
'to return an array of the tokens (Words) in a dellimited list of values
'the delimiter may be set by the user. The default value for the dilimiter
'is a single space. The Delimiter may be set to any string, however only the
'first character of the string is used.
'Michael Red, 9/25/00 for the Duvall Group, Columbia, MD
'Usage & Example
'MyArray = basSplit("Me, Myself, Thee, Thou, Though, Go, This is a test", ",")
'For xx = 0 To UBound(MyArray): Print xx, MyArray(xx): Next xx
'0 Me
'1 Myself
'2 Thee
'3 Thou
'4 Though
'5 Go
'6 This is a test
Dim Idx As Integer
Dim Dlm As Integer
Dim PrvDlm As Integer
Dim WdsDone As Boolean
Dim WdAray() As String
DelimChar = Left(DelimChar, 1)
Idx = 0 'Init WdAray Index
PrvDlm = 0 'Start w/ Prev pos of Delim Before String
ReDim WdAray(Idx) 'Initalize array of Words to single element
While Not WdsDone
Dlm = InStr(PrvDlm + 1, StrIn, DelimChar)
If (Dlm = 0) Then 'Can't find any more dellimiters.
'Must be done. Just add the remainder of the Input
WdAray(Idx) = Right(StrIn, Len(StrIn) - (PrvDlm))
WdsDone = True 'Tell'em were done here
Else
'Somewhere in the midst of all this, we jave found a "Real" word
WdAray(Idx) = Mid(StrIn, PrvDlm + 1, ((Dlm - 1) - (PrvDlm - 1)) - 1)
Idx = Idx + 1
ReDim Preserve WdAray(Idx)
PrvDlm = Dlm
End If
Wend
If (WdAray(Idx) = "") Then
ReDim Preserve WdAray(Idx - 1) 'Remove (Unused) last array element
End If
basSplit = WdAray
End Function