Tools Links Login

Enhanced Split Function (2D) (Fixed)

This code is an addon to the "split" function in VB, it takes an string and will split it into a 2D array. It's pretty easy to figure out. I wasn't sure whether to put this as a beginner or intermediate so it is kinda inbetween. If you're using VB5 or before you'll need to download a replacement split function from this site somewhere.
Latest - Fixed a small problem with different sizes of one dimension (could have been fixed with on error resume next but this is more effective)

Original Author: Paul Robins

Code

Private Function Split2D(StringToSplit, FirstDelimiter, SecondDelimiter)
Dim X As Integer, _
  Y As Integer, _
  FirstBound As Integer, _
  SecondBound As Integer, _
  ResultArray()
temparray = Split(StringToSplit, FirstDelimiter)
FirstBound = UBound(temparray)
For X = 0 To FirstBound
  temparray2 = Split(temparray(X), SecondDelimiter)
  If UBound(temparray2) > SecondBound Then SecondBound = UBound(temparray2)
Next
ReDim ResultArray(FirstBound, SecondBound)
For X = 0 To FirstBound
    temparray2 = Split(temparray(X), SecondDelimiter)
  For Y = 0 To UBound(temparray2)
    ResultArray(X, Y) = temparray2(Y)
  Next
Next
Split2D = ResultArray
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 85 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.