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

Martyn Haigh martyn.haigh at virgincosmetics.com
Tue Dec 24 07:05:01 CST 2002


Chris

I've had problems with this one too.  Here's what I found.

If you use the Preserve keyword, you can resize only the last array
dimension, and you can't change the number of dimensions at all. For
example, if your array has only one dimension, you can resize that dimension
because it is the last and only dimension. However, if your array has two or
more dimensions, you can change the size of only the last dimension and
still preserve the contents of the array. The following example shows how
you can increase the size of the last dimension of a dynamic array without
erasing any existing data contained in the array.

ReDim X(10, 10, 10)
. . .
ReDim Preserve X(10, 10, 15)

My head hurts a little bit - so I won't be able to offer an answer at the
moment!  I hope this little bit of help can get you to come up with a
different solution.

Good luck!

Martyn Haigh

Site Developer
The Virgin Cosmetics Company
City Fields, Chichester, West Sussex PO20 2FP
tel: 01243 622282

The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution or any action taken or omitted to be taken in reliance
on it, is prohibited and may be unlawful.


-----Original Message-----
From: Chris Marsh [mailto:chris at webbtech.co.uk]
Sent: 24 December 2002 12:37
To: thelist at lists.evolt.org
Subject: [thelist] [ASP] Dynamically resizing multi-dimensional array

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


--
* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester
and archives of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !



More information about the thelist mailing list