Thanks, Ron!
Dave
At 02:09 PM 4/30/2012, you wrote:
Truth be told, if you use redim you never even have to specify a
maximum depth. Just pick a reasonable starting size and if your
stack ever wants to get deeper than that, redim/preserve it to
double the size. ("Reasonable starting depth" is defined as whatever
the sweet spot between performance and memory usage is for your
application. That's something that may be worth parameterizing, if
you wish.) Optionally, when your stack empties to less than half its
size, redim it smaller (but not below that minimum size.)
But redim is also the answer to the question you asked. You do
something like this:
' -------------------------------------
class stackThingy
private maxDepth
private curDepth
private stuff()
public default function init( size )
maxDepth = size
curDepth = 0
redim stuff(size)
set init=me
end function
public sub showsize
msgbox "The current size is " & maxDepth & vbcrlf & "The
array is dimmed to " & ubound(stuff)
end sub
end class
set blah = (new stackThingy)(20)
blah.showsize
' -------------------------------------
On 4/30/2012 4:42 PM, David Helkenn wrote:
Thanks, Ron,
I don't think so. It is more like instantiating a stack class with
each instance of that class (a stack object) having a "MaxDepth"
space allocated to it. Then each time I "NEW CLS_Stack", I would
get a stack object of "MaxDepth" elements. (I am ignoring the
TopOfStack, Push, Pop, etc. for now.)
What I think I'm hearing from Doug and Aaron is that the stack is
actually defined outside the context of the class. If I then want
a stack of "MaxDepth", I have to call the "CLS_Stack.Init
(MaxDepth)" in order to obtain an array named S5. I think I then need:
SET S5 = (NEW CLS_Stack).Init(MaxDepth)
which will make S5 an array of "MaxDepth" elements. So, my
confusion and question really comes down to, "Where do I declare
the array that is my stack?" I thought I could do it inside the
Class block, hopefully parameterizing the class somehow so that I
could have something like:
SET S5 = NEW CLS_Stack(MaxDepth)
and
Set S12 = NEW Cls_Stack(MonthsPerYear)
etc.
I understand this is not permitted as VBS does not support
parameterizing a class. This is a shame IMHO because so many
classes seem to be a natural "List" of other objects.
Redim can certainly handle the dynamic fluctuations in the depth of
a stack, but that seems to me to be operative only after the stack
is set up in the first place.
I can imagine a whole collection of objects organized in all manner
of data structures -- queues, trees, graphs, ... All of these
structures could be restricted to a given, well defined, set of
some number of objects.
So, on to the WIKI articles which I assume are at AppCentral. Thanks,
Aaron, for that lead.
Dave
At 11:01 AM 4/30/2012, you wrote:
On 4/30/2012 1:52 PM, David Helkenn wrote:
private someStack ' AARRGGGG how many?
Does redim solve this problem for you?
http://msdn.microsoft.com/en-us/library/c850dt17%28v=vs.84%29.aspx