Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

Vectors in ASP?

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
dbnewbie
Asked:
dbnewbie
  • 2
1 Solution
 
glottisCommented:
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
 
GaryCommented:
Depending on your code they may be a nicer way to do this rather than redimming an array constantly in a loop
0
 
sybeCommented:
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

    Public Function Add(Byval v)
        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
 
sybeCommented:
<%
Dim oVector, MyArray, i
Set oVector = new Vector
oVector.Add("somevalue")
oVector.Add("someothervalue")

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

%>
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now