Split(StringToSplit[, DelimiterToUse, HowMany])
- Returns a one dimensional array
- StringToSplit is any valid string
- DelimiterToUse is the character that you want the string to be split by.
- HowMany is the number of elements you want to limit the array to.
- DelimiterToUse and HowMany are optional parameters.
- If you leave out the DelimterToUse, the function uses a space to split the string.
Example:
Dim MyString, MyArray
MyString = "apples,oranges,grapes"
MyArray = Split(MyString, ",")
Result:
A one dimensional array called MyArray with 3 elements.
No, Split() is new with VB 6.0, not found in VB 5.0. There are several functions that were added to VB 6.0 - this is one of the reasons why the forum asks you for your VB version and shows it as part of your profile- so the answers you get match your version of VB.
Try:
Code:
'Here's one of a dozen versions of Split()
Sub Split(ByVal arr() As String,ByVal strInput as String, ByVal strDelimit as String)
Dim i, tmp
Redim arr(0)
For i = 1 to len(strInput)
tmp = mid(strInput,i,1)
if tmp = strDelimit then
Redim Preserve arr(Ubound(arr) + 1)
arr(UBound(arr) ) = ""
else
arr(Ubound(arr)) = arr(Ubound(arr)) & tmp
End If
Next i
End Sub
Yes, those of us who don't need the fluff of VB6 (J/K) have it hard sometimes. Most apparent is the absense of Replace and the mentioned Split. Attached is a file I use for VB6 source called VB6Compatibility.bas. Just add it to a project and you have instant Split and Replace!
BTW, I didn't write the code. I came accross Replace here on VB Forums and Split on My Favorite Function 3 from VB World.
Brian Programming: VB5 Pro (SP3) - QBasic 1.1,4.5 Internet: HTML 4, CSS, JavaScript
Visit AltInt.com!
Here's the new and improved VB6Compatibility.bas file! According to VB Speed, these are (in general) the fastest code segments available. There are only a few reasons why the fastest wouldn't be contained in here:
1) Requires a TLB. Reason: I don't like 'em.
2) Requires an External class. That defeats the purpose of having a drop in file code module.
3) Lenth of code. A 10k function that goes 2x as fast as a 1k module doesn't quite seem like a good trade off to me.
Anyway, here it is. VB6Compatibility.1
Note, both original functions have been replaced with faster code.
Brian Programming: VB5 Pro (SP3) - QBasic 1.1,4.5 Internet: HTML 4, CSS, JavaScript
Visit AltInt.com!