I'm having problems accessing the dynamic array below. The MsgBox
inside the loop in the subroutine "ReadCSVFile" I get the correct value
for index 1 for "arrFieldName". Any other attempt to access that array
index, even the one at the end of the subroutine, returns blank. I'm
obviously doing something bone headed here but I can't figure it out

' VB Script Document
option explicit

Dim objFSO
ReDim arrPrompt(0), arrFieldName(0), arrTyp(0), arrSize(0), arrDesc(0),
arrDef(0)
ReDim arrCusLay(0), arrLayField(0), arrInst(0), arrExcpt(0)
' Fileopen constants
Const ForReading = 1
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")

ReadCSVFile ("cusmas_form4.csv")

Sub ReadCSVFile ( TableName )
Dim i, arrRecord
Dim objInFile
Set objInFile = objFSO.OpenTextFile(TableName, ForReading)

ReDim arrPrompt(0)
ReDim arrFieldName(0)
ReDim arrTyp(0)
ReDim arrSize(0)
ReDim arrDesc(0)
ReDim arrDef(0)
ReDim arrCusLay(0)
ReDim arrLayField(0)
ReDim arrInst(0)
ReDim arrExcpt(0)
i=0

Do Until objInFile.AtEndOfStream
arrRecord = split(objInFile.ReadLine, "|")

arrPrompt(i)= arrRecord(0)
arrFieldName(i) = arrRecord(1)
arrTyp(i) = arrRecord(2)
arrSize(i) = arrRecord(3)
arrDesc(i) = arrRecord(4)
arrDef(i) = arrRecord(5)
arrCusLay(i) = arrRecord(6)
arrLayField(i) = arrRecord(7)
arrInst(i) = arrRecord(8)
arrExcpt(i) = arrRecord(9)

if ( i = 1 ) then
MsgBox(arrFieldName(1))
end if

i=i+1
ReDim arrPrompt(i)
ReDim arrFieldName(i)
ReDim arrTyp(i)
ReDim arrSize(i)
ReDim arrDesc(i)
ReDim arrDef(i)
ReDim arrCusLay(i)
ReDim arrLayField(i)
ReDim arrInst(i)
ReDim arrExcpt(i)
loop
MsgBox(arrFieldName(1))
End Sub

Re: Dynamic Array by Bob

Bob
Thu Dec 14 16:04:29 CST 2006

steve.holle@gmail.com wrote:
> I'm
> obviously doing something bone headed here but I can't figure it out


Yeah, that may be an apt description.

The Redim statement has this optional keyword, "Preserve"...



Bob
--