[thelist] [ASP] Dynamically resizing multi-dimensional array

Chris Marsh chris at webbtech.co.uk
Tue Dec 24 06:42:00 CST 2002


Dear all

I'm trying to read information from a CSV file and create a
multi-dimensional array with it. My code is as follows:

Function GetDef()
	Dim oFSO, oFile, oTSO, sDef
	Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
	If Not oFSO.FileExists(Application("PATH_DEFINITION")) Then
		GetDef = Null
		Exit Function
	End If
	Set oFile = oFSO.GetFile(Application("PATH_DEFINITION"))
	If oFile.Size = 0 Then
		GetDef = Null
		Exit Function
	End If
	Set oTSO = oFile.OpenAsTextStream(1, 0)
	Redim aDefinition(0, 0)
	Dim sDefRec, aDefRec, iCount
	Do While Not oTSO.AtEndOfStream
		sDefRec = oTSO.ReadLine
		aDefRec = Split(sDefRec, ",")
		Redim Preserve aDefinition(oTSO.Line - 2,
UBound(aDefRec))

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		For iCount = 0 To UBound(aDefRec)
			aDefinition(oTSO.Line - 2, iCount) =
aDefRec(iCount)
		Next
	Loop
	GetDef = aDefinition
	Set oFile = Nothing
	Set oTSO = Nothing
	Set oFSO = Nothing
End Function

I've tested just about everything with response.write, and the only
thing that doesn't seem to work is the indicated line. It works in the
first pass of the loop, (tried with an Exit Do after the indicated line)
but when I try to resize aDefinition after this dynamically, I get a
"Subscript out of range" error. I'm having trouble locating a
tutorial/article on resizing dynamic arrays, but I assume I'm trying to
go about this the wrong way. Can anyone enlighten me?

Many thanks, and yuletide greetings or whatnot...

Regards

Chris Marsh





More information about the thelist mailing list