View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Multi-Dimensional Array

noname wrote on 10/16/2011 :
Hi,

I am trying to parse a SAS output text file (running into 4,00,000
lines containing multiple combinations), into a multi-dimensional
array (4 dimensions). i know that only the last dimension can be
increased and the middle dimensions are fixed.

My question is how do i redim preserve the middle dimensions (1st, 2nd
and 3rd)? i have seen people use Transpose function with 2 dimensions.
but i came to know it has its limitations when it comes to size of
data. so is there a function UDF to change the 1st 3 dimensions
dynamically while adding / removing data?

please let me know if someone has tried this before.


I'd prefer to 'dump' the entire file into a Variant (resulting in a
zero-based array) and parse each line as per need dictates. So each
line in the text file is an element of the array, and each element gets
parsed according to its delimiter.

Example <aircode:
'Get the text
Const sFilename As String = "C:\SAS.txt"
Dim sFileText As String
sFileText = ReadTextInFile(sFilename)
'..where 'ReadTextInFile()' is a function that takes a filename arg

'Dump file contents into an array
Dim vTextIn As Variant
vTextIn = Split(sFileText, vbCrLf)

'Parse the array one element at a time
Dim n As Long, x As Long, v As Variant
Const sDelimiter As String = vbTab '//edit to suit
For n = LBound(vTextIn) To UBound(vTextIn)
v = Split(vTextIn(n), sDelimiter)
For x = LBound(v) To UBound(v)
'//do stuff code goes here
Next 'x
Nxt 'n

This way you don't have to dimension arrays. You could even create each
element in vTextIn as an array, resulting in an array of arrays.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc