Public Function basNewArray(filIn As String) As Variant
Dim FilId As Integer
Dim Idx As Integer
Dim Jdx As Integer
Dim Kdx As Integer
Dim RawFile As String
Dim MyLines As Variant
Dim MyWords As Variant
Dim TempArray(100, 7) As Variant
Dim Mu() As Variant
'I 've an array mu(MAX_1,MAX_2) where MAX_1=100,MAX_2=7
'However once I've assigned calculations to it it may turn out that
'the first index is 2 and the second is 5.
'How do I redim preserve such an array?
'If I leave it it just prints out about 700 zeros, and I know that
'you can only redim preserve the second index in a 2-dim array.
'SAMPLE Usage:
'? basNewArray("C:\My Documents\Fleas.Txt")
'C:\My Documents\Fleas.Txt is listed below
'My Dog Has Fleas
'Your Dog Has Fleas
'His Dog Has Fleas
'All Dogs Have Fleas
'This Cat Has Fleas
'That Cat Has Fleas
'Those Cats Have Fleas
'Who Doesn 't Have Fleas
'I Don 't Have Fleas
FilId = FreeFile 'File Handle
Open filIn For Binary As FilId 'Open File
RawFile = Space(LOF(FilId)) 'Assign File String proper Length
Get #FilId, 1, RawFile 'Get File into String
MyLines = Split(RawFile, vbCrLf) 'Split file into an Array of Strings
Idx = 0 'Initalize Index for String array
Jdx = 0 'Initalize the "Mu" ArrayFirst Index (100)
Do While Idx <= UBound(MyLines) 'Loop structure for array of Lines
MyWords = Split(MyLines(Idx)) 'Split the line into an array or "Words"
Kdx = 0 'Initalize the second Index (7) for "Mu"
Do While Kdx <= UBound(MyWords)
TempArray(Idx, Kdx) = MyWords(Kdx) 'Populate the Temp Array
Kdx = Kdx + 1
Jdx = basMaxVal(Jdx, Kdx) 'Keep Max value for "Word" index
Loop
Idx = Idx + 1 'Increment the Lines array Index
Loop
'Adjust the Idx TO the TRUE Index Value
Idx = Idx - 1
'Arrive Here w/
'Idx ~ Max for the First Array Index AND
'Jdx ~ Max for the Second array Index
ReDim Mu(Idx, Jdx) 'Re-Dim the "Mu" Array w/ Proper dimensions
Idx = 0
Do While Idx <= UBound(Mu, 1)
Jdx = 0
Do While Jdx <= UBound(Mu, 2)
Mu(Idx, Jdx) = TempArray(Idx, Jdx)
Jdx = Jdx + 1
Loop
Idx = Idx + 1
Loop
End Function