 |

10-24-2003, 10:27 AM
|
|
Newcomer
|
|
Join Date: Oct 2003
Posts: 1
|
|
an array of dynamic arrays!?
|
|
Ok first hey all, /me is new to this forum
I'm writing an ASP script that takes a recordset out of a database, then sorts in into few types of arrays.. doesn't really matter really
I've been trying for 2 days now to creat an array of dynamic arrays.
Point is, it will be better to have a dynamic array of dynamic arrays, but even if I can make say, an array of 6 dynamic arrays it's good enough.
Now, don't give me the solution like:
Dim arr()
reDim(8,9)
because the whole point is, first I can tell what is the first dymention of the array (the 8) then, I don't know what will be the size of any other array until I fill it...
I tried everything that came to mind... If only I had pointers like C
help please?
|
|

10-27-2003, 06:49 AM
|
|
Contributor
|
|
Join Date: Jul 2003
Location: Southampton UK
Posts: 795
|
|
Im just getting into asp so im not sure what to say specifically about it but I would suggest a different data type. Im not sure what your up to but my guess is your looking for one like a collection instead of an array.
|
__________________
Chris
|

10-28-2003, 08:45 AM
|
|
Newcomer
|
|
Join Date: Oct 2003
Posts: 1
|
|
|
|
OK, I`m quite new to this subject as well.
The problem is, that when you use redim to resize, all previously stored data is lost, however, if you use something like "redim preserve", it might work. The size is changed, and the data preserved.
This is probably not what you are looking for, but perhaps you could have some use from it....
gr.
Joris
Quote: Originally Posted by barakuda Ok first hey all, /me is new to this forum
I'm writing an ASP script that takes a recordset out of a database, then sorts in into few types of arrays.. doesn't really matter really 
I've been trying for 2 days now to creat an array of dynamic arrays.
Point is, it will be better to have a dynamic array of dynamic arrays, but even if I can make say, an array of 6 dynamic arrays it's good enough.
Now, don't give me the solution like:
Dim arr()
reDim(8,9)
because the whole point is, first I can tell what is the first dymention of the array (the 8) then, I don't know what will be the size of any other array until I fill it...
I tried everything that came to mind... If only I had pointers like C 
help please?
|
|

10-28-2003, 04:43 PM
|
|
Regular
|
|
Join Date: Oct 2003
Location: Penticton, B.C. Canada
Posts: 83
|
|
Please post some code so that we know what you are talking about a little better. I have an idea what you are talking about but would like you to be more specific about what the requirements of the solution you are looking for.
here is a dynamic array of dynamic arrays being created from a recordset
You are going to have to expand the concepts here, and I may have left the code unfinished, I got interupted while writing this. The good thing is that I create and array of dynamic arrays, and I think I did a good job of it. I am fairly adept at doing this type of thing so gimme some example output if you have any further questions and I'll try and pound out some code.
Code:
dim arrParents
dim arrTables
dim iCount, iRS1, iRSParent ' used to get number of records
iCount = 0
do while not rs.EOF
iCount = iCount + 1
rs.movenext
loop
iRS1 = iCount
on error resume next
rsParent.MoveFirst
RS1.MoveFirst
RS2.MoveFirst
on error goto 0
dim SQL
SQL = "Select * From [ParentTableName]"
set rsParent = Conn.Execute SQL
iCount = 0
do while not rsParent.EOF
iCount = iCount + 1
rsParent.MoveNext
loop
iRsParent = iCount
Redim arrParent(iRsParent) ' 1 based array element 0 not used
on error resume next
rsParent.MoveFirst
on error goto 0
iCount = 0
dim arrFields
dim i,j
dim arrParentTableNames
arrParentTableNames = Array("Parent1", "Parent2", "Parent3")
dim rsTable
for i = 0 to Ubound(arrParentTableNames)
SQL = "Select * From [" & arrParentTableNames(i) & "]"
set rsParent = Conn.Execute(SQL)
do while not rsParent.EOF
iCount = iCount + 1
arrTables = getArrNew(2) ' 1 based array element 0 not used
SQL = "Select * From [Table1Name]"
set rsTable = Conn.Execute(SQL)
arrFields = getArrNew(rs1.Fields.Count)
for i = 0 to rs1.Fields.Count - 1
arrFields (i + 1) = rs1.Fields(i).Value
next
arrTables(1) = arrFields
SQL = "Select * From [Table2Name]"
set rsTable = Conn.Execute(SQL)
arrFields = getArrNew(rs1.Fields.Count)
for i = 0 to rs1.Fields.Count - 1
arrFields (i + 1) = rs1.Fields(i).Value
next
arrTables(2) = arrFields
arrParents(
rsParent.MoveNext
loop
next
Function getArrNew(NewSize)
Dim X
Redim X(NewSize)
getArrTable = X
End Function
Quote: Originally Posted by barakuda Ok first hey all, /me is new to this forum
I'm writing an ASP script that takes a recordset out of a database, then sorts in into few types of arrays.. doesn't really matter really 
I've been trying for 2 days now to creat an array of dynamic arrays.
Point is, it will be better to have a dynamic array of dynamic arrays, but even if I can make say, an array of 6 dynamic arrays it's good enough.
Now, don't give me the solution like:
Dim arr()
reDim(8,9)
because the whole point is, first I can tell what is the first dymention of the array (the 8) then, I don't know what will be the size of any other array until I fill it...
I tried everything that came to mind... If only I had pointers like C 
help please?
|
|

10-28-2003, 05:44 PM
|
|
Regular
|
|
Join Date: Oct 2003
Location: Penticton, B.C. Canada
Posts: 83
|
|
Here is another technique you could use, or even modify to your own liking: There is a better way to do this that I have seen, but I have to test it to answer a few questions first. I have not tested the code below so you might have to do a little debugging.
Code:
Class ArrayElement
private mPtr
public Var
Private Sub Class_Initialize()
mPtr = Null
Var = Empty
End Sub
Private Sub Class_Terminate()
End Sub
Public Property Set ptr(newPtr)
set mPtr = newPtr
End Property
Public Property Get ptr()
if IsObject(ptr) then
set ptr = mPtr
else
ptr = mPtr
end if
End Property
End Class
Function get_ArrayElement()
dim x
set x = new ArrayElement
set get_ArrayElement = x
End Function
Class aspArray
private mStartArrElem
private mLastArrElem
private iUbound
Private Sub Class_Initialize()
mStartArrElem= get_ArrayElement
set mLastArrElem = mStartArrElem
iUBound = 1
End Sub
Private Sub Class_Terminate()
End Sub
Public Function Item(iPos) ' 1 based
if iPos > iUbound or iPos < 1 then
Err.Raise 10001, "aspArray", "Invalid index."
Exit Sub
end if
dim ArrElemCurr
set ptrCurr = mStartArrElem
if iPos = 1 then
Item = ArrElemCurr.Var
Exit Function
end if
dim i
for i = 2 to iPos
set ArrElemCurr = mStartArrElem.ptr
next
Item = ArrElemCurr.Var
End Function
Public Sub Add(newVar)
dim ArrElem
set ArrElem = get_ArrayElement
If IsObject(newVar) then
set ArrElem.Var = newVar
else
ArrElem.Var = newVar
end if
set mLastArrElem.ptr = ArrElem
set mLastArrElem = mLastArrElem.ptr
iUbound = iUbound + 1
End Sub
Public Property et UBound()
UBound = iUbound
End Property
End Class
' Usage
dim objArray
set objArray = new aspArray
objArray.Item(1).Value = "Hello World 01"
objArray.Add("Hello World 02")
dim i
for i = 1 to objArray.Ubound
Response.Write objArray.Item(i) & "<br>" & vbnewline
next
This technique might make you consider using the dictionary object to do your array of arrays. because of the ability to add an element of any type to it. For example you could add another full dictionary object therby creating a dynamic data structure like your dynamic array of arrays.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
| |
|