Results 1 to 3 of 3

Thread: Split()

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    42

    Angry

    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



    Using VB6 Professional Ediion

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    42

    Thumbs up Thanks!

    It works - as reported!!

    Old Man
    Using VB6 Professional Ediion

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width