-
I'm using VB4 and am trying to use a replacement function for VB6's split().
The error messaage I get is that I cannot assign to a non-byte array. In essense what I'm doing is:
Dim x(5)
x=Split("1/11/2000","/")
msgbox x(1)
Need any and all help,
Old Man
-
<?>
You can't use VB6 functions in 4
Also, you don't declare the split variable as an array
It must be declared as a variant
Code:
'split function for VB5 and under vb6 has the function
'posted originally by Aaron Young
Public Function Split2(ByVal sString As String, ByVal sSeparator As String) As Variant
Dim sParts() As String
Dim lParts As Long
Dim lPos As Long
lPos = InStr(sString, sSeparator)
While lPos
ReDim Preserve sParts(lParts)
sParts(lParts) = Left(sString, lPos - 1)
sString = Mid(sString, lPos + Len(sSeparator))
lPos = InStr(sString, sSeparator)
lParts = lParts + 1
Wend
If Len(sString) Then
ReDim Preserve sParts(lParts)
sParts(lParts) = sString
End If
Split2 = IIf(lParts, sParts, Array())
End Function
'Example:
Private Sub Form_Load()
Dim x as string , y as Variant
x = "1999/12/12"
y = split2(x,"/")
End Sub
You should end up with
y(0) = 1999
y(1) = 12
y(2) = 12
-
Thanks!
It works - as reported!!
Old Man