Solved

Vectors in ASP?

Posted on 2003-11-21
4
283 Views
Last Modified: 2006-11-17
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
Comment
Question by:dbnewbie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
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

by:Gary
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

by:sybe
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

    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
 
LVL 28

Expert Comment

by:sybe
ID: 9802705
<%
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Questions about INCLUDE FILES 2 47
Html form and modal / img src -problem 3 60
ASP and Extracting XML 7 47
Save data in two Database, Asp 2 71
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question