Solved

# Vectors in ASP?

Posted on 2003-11-21
277 Views
How do I implement vectors in ASP? I don't want to declare a very large array just to make sure I am able to accomodate my needs.
0
Question by:dbnewbie
• 2

LVL 2

Accepted Solution

glottis earned 25 total points
ID: 9801639
the way i do it is:

reDim myVector(10)

for i=0 to 100
if UBound(myVector) < i then
reDim preserve myVector(i*2)
end if
myVector(i) = "some data"
next

This is just the basic idea... meaning you can redeclare the variable with the keyword "preserve".
0

LVL 58

Expert Comment

ID: 9802197
Depending on your code they may be a nicer way to do this rather than redimming an array constantly in a loop
0

LVL 28

Expert Comment

ID: 9802581
You can create your own Class with VBScript. Something like this (i did not test it, but for 25 points you can't expect tested code....)

Class Vector
Private aArray, iIncrementWith, iLastIndexUsed

Private Sub Class_Initialize
ReDim aArray(-1)
iIncrementWith = 10
iLastIndexUsed = -1
End Sub

Private Sub Class_Terminate
Erase aArray
End Sub

If iLastIndexUsed + 1 > Ubound(aArray) Then ReDim Preserve aArray(Ubound(aArray)+iIncrementWith)
aArray(iLastIndexUsed + 1) = v
iLastIndexUsed = iLastIndexUsed + 1
End Function

Public Default Property Get Array
ReDim Preserve aArray(iLastIndexUsed)
Array = aArray()
End Property

End Class
0

LVL 28

Expert Comment

ID: 9802705
<%
Dim oVector, MyArray, i
Set oVector = new Vector

MyArray = oVector
For i = 0 To Ubound(MyArray)
Response.write MyArray(i) & "<br>"
Next

%>
0

## Featured Post

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…