Results 1 to 3 of 3

Thread: create Split function

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    4
    I would like to create a function that parses a string into an array like the split function (vb v6).
    ex: "12 5 8 14"
    This string is delimited by spaces. The resulting array would contain. myArray(1)=12 myArray(2)=5 etc.

    Thanks

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

    <?>

    Aaron Young posted this a few days ago..perhaps you can use it.
    Code:
    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 vLines As Variant
        Dim lLine As Long
        
        vLines = Split2("Line1,Line2,Line3", ",")
        For lLine = 0 To UBound(vLines)
            List1.AddItem vLines(lLine)
        Next
    End Sub
    "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
    New Member
    Join Date
    Nov 2000
    Posts
    4
    Thanks for the code. It works great!

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