
Change Array to Multidimensional Array
I found a split function to use with a delimited file (because I'm
using Word 97 so can't use Split())
At the end of the function I have each item from the file stored in an
array but I need it to be in a multidimensional array so that I can
use it elsewhere.
The file looks as follows:
Item1,tel1,fax1
Item2,tel2,fax2
Item3,tel3,fax3
And when in the array it looks like:
Item1,tel1,fax1,Item2,tel2,fax2,Item3,tel3,fax3
However I would like it to be like:
MyArray(0)(0) = Item1
MyArray(0)(1) = tel1
MyArray(0)(2) = fax1
MyArray(1)(0) = Item2
etc
etc
Could you show/point me to a method to move the items from the
original array to the multidimensional array
OR alternatively could you show me how to modify the function to
insert each item correctly in the multi array
Function SplitString(Value As String, Optional SplitChr As String =
";") As Variant
On Error Resume Next
Dim Pos As Long
Dim Start As Long
Dim Length As Long
Dim Cnt As Long
Dim Result As String
Dim ResultArray() As Variant
ReDim Preserve ResultArray(Cnt) As Variant
Start = 1
Do
Value = Trim(Value)
Length = Len(Value)
If Length = 0 Then Exit Do
Pos = InStr(Start, Value, SplitChr)
Select Case Pos
Case 0
ReDim Preserve ResultArray(Cnt) As Variant
If (Not Value = Empty) Then ResultArray(Cnt) = Value
Exit Do
Case Else
Result = Strings.Left(Value, Pos - 1)
If (Not Result = Empty) Then
ReDim Preserve ResultArray(Cnt) As Variant
ResultArray(Cnt) = Result
Cnt = Cnt + 1
End If
Value = Right(Value, Length - Pos)
End Select
Loop
SplitString = ResultArray
End Function
Any help is most appreciated
thnxs
Mark.