Hi Andrew,
If you are comfortable with the solution, go with it. Not many people
leverage that particular capability of a property. It sure can be a
powerful tool.
In this instance, I rejected that approach because it seemed to make
more sense to move the calculation of the pressure into the class
module rather than have each client duplicate that work. However, you
know your application better than I do and if it makes sense to you...
--
Regards,
Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
In article <9dfb6bbd.0409061644.14a3aa@posting.google.com>, hooksie2
@hotmail.com says...[color=blue]
> Steve, Tushar,
>
> Thanks alot for the time and effort you've put into your responses. I
> have mucked around with the 'Property Let' statement some more and
> finally figured out how optional parameters work, ie.
>
> Public Property Let Pressure(Optional Source as Integer = 1, Value As
> single)
>
> This is quite nice because most people typing "Stream.Pressure = 100"
> from a std module will likely not even notice the optional "Source"
> parameter. If they do then I will enumerate the constants (+ provide
> help) so that shouldn't provide too much confusion. However, when
> setting pressure from some other object I can pass source and store it
> in the receiving object (after checking for inconsistencies). This
> will avoid having to keep track of the active object external to the
> objects themselves.
>
> In case you're interested my code will look something like:
>[color=green][color=darkred]
> >> clsPipe <<[/color][/color]
> Private With Events p_objStrmIn As clsStream
> Private With Events p_objStrmOut As clsStream
>
> Private Sub objStrmIn_PressureChange()
> ' try to calculate dP - If successful (ie. all other rqd values
> available)...
> p_objStrmOut.Pressure(Source:=2) = p_objStrmIn.Pressure + dP
> ' will need some additional checking since this will trigger the
> outlet stream
> ' event
> ' objStrmOut will raise an error if there is a conflict in source
> End Sub
> Private Sub objStrmOut_PressureChange()
> ' As per above but calculate StrmIn pressure
> End Sub
>[color=green][color=darkred]
> >> clsStream <<[/color][/color]
> Public Property Let Pressure(Optional Source as Integer = 1, Value As
> single)
> ' Check for inconsistencies
> ' Store the value & source where default source (=1) is user input
> RaiseEvent PressureChange
> End Property
>
> This avoids needing the CalculatePressure sub. Pressure is returned
> via the same attribute whether calculated or input.
>
> Thanks for all the input and thanks for the powerpoint example of
> stacks - can relate to that one.
>
> Andrew
>
> Tushar Mehta <tmUnderscore200310@tushar-mehta.SeeOhEm> wrote in message news:<MPG.1ba50a28c10e7d97989938@news-server.rochester.rr.com>...[color=green]
> > Specific to your problem...
> >
> > How have you implemented the In/Outlet and the Pipe entities? Are
> > Inlet and Outlet members of the same class? I assume Pipe is a
> > separate class. Would that be correct?
> >
> > Suppose the In/Outlets are members of the class InOutLet. Then, that
> > class module might contain something like:
> >
> > Option Explicit
> >
> > Dim PressureBasedOn As Integer, dPressure As Double
> > Const cPressureSpecified As Integer = 1, _
> > cPressureCalculated As Integer = 2, _
> > cPressureUnknown As Integer = 0
> >
> > Property Get Pressure() As Double: Pressure = dPressure: End Property
> > Property Let Pressure(ByVal uPressure As Double)
> > Select Case PressureBasedOn
> > Case cPressureUnknown:
> > dPressure = uPressure
> > PressureBasedOn = cPressureSpecified
> > Case cPressureSpecified: dPressure = uPressure
> > Case cPressureCalculated:
> > 'Set error condition vis-a-vis specifying a calculated value
> > MsgBox "Cannot specify a calculated value!"
> > Case Else:
> > 'System integrity error; PressureBasedOn has unexpected value!
> > End Select
> > End Property
> >
> > Public Sub calculatePressure(ByVal StartPressure As Double, _
> > ByVal PressureDrop As Double)
> > Select Case PressureBasedOn
> > Case cPressureUnknown:
> > dPressure = StartPressure + PressureDrop
> > PressureBasedOn = cPressureCalculated
> > Case cPressureSpecified:
> > 'Set error condition vis-a-vis calculating a specified value
> > MsgBox "Cannot calculate a specified value"
> > Case cPressureCalculated:
> > dPressure = StartPressure + PressureDrop
> > Case Else:
> > 'System integrity error; PressureBasedOn has unexpected value!
> > End Select
> > End Sub
> >
> > For test purposes, use something like:
> >
> > Option Explicit
> >
> > Sub testIt()
> > Dim x As New InOutLet
> > x.Pressure = 10
> > x.calculatePressure 10, 1
> > MsgBox x.Pressure
> > Set x = New InOutLet
> > x.calculatePressure 10, 1
> > x.Pressure = 10
> > MsgBox x.Pressure
> > End Sub
> >
> >
> > --
> > Regards,
> >
> > Tushar Mehta
> >
www.tushar-mehta.com
> > Excel, PowerPoint, and VBA add-ins, tutorials
> > Custom MS Office productivity solutions
> >
> > In article <9dfb6bbd.0409040153.6d597b75@posting.google.com >, hooksie2
> > @hotmail.com says...[color=darkred]
> > > To clarify...
> > > First up - I am working with vba running in xl.
> > >
> > > I have been working my way through Ken Getz & Mike Gilbert's book, the
> > > "VBA Dev's Handbk", over a period of time. Here I came across an
> > > example of how to implement your own stack using two class objects.
> > > So, from a learning point of view I am curious to know more about when
> > > and for what you would use a stack. I can see (from the example) how
> > > this could be used within standard modules although am not so sure why
> > > you want to do that really. Bob's reply seems to indicate that as
> > > well. In parallel, however, I am writing my own program - hopefully
> > > applying some of what I learn along the way. My code is object based
> > > so as part of my understanding of stacks I am curious as to whether a
> > > custom stack can be used with class objects. As far as I can tell
> > > this would be overly arduous.
> > >
> > > Then comes my project specific question which I thought could be
> > > solved by maintaining a stack - but you are right there may be a
> > > completely different and more optimal solution out there.
> > >
> > > Say I have 2 objects: cStream and cPipe. I create two instances of
> > > cStream, Inlet and Outlet and one instance of cPipe, MyPipe. Pointers
> > > to Inlet and Outlet are held by MyPipe. When the inlet stream is
> > > passed a pressure value an event is raised which is picked up by
> > > MyPipe. If MyPipe is able to calculate the pressure drop across it,
> > > dP, then it should pass the downstream pressure to the outlet stream
> > > (ie. Outlet.Pressure = Inlet.Pressure + Me.dP). Conversely, if outlet
> > > pressure is set then inlet pressure should be calculated.
> > >
> > > The trick is though, I need to also record where the outlet pressure
> > > (or inlet pressure) came from because if Outlet.Pressure is calculated
> > > but then someone tries to enter a value for it then I need to raise an
> > > error. But I don't want to raise an error if inlet pressure is
> > > changed and a new outlet pressure is calculated. This is where I
> > > thought a stack could be of use.
> > >
> > > Sincere apologies for kind of confusing two questions in one.
> > >
> > > Thanks for your help,
> > > Andrew
> > >
> > >
> > > "Tom Ogilvy" <twogilvy@msn.com> wrote in message news:<#REx4kckEHA.524@TK2MSFTNGP15.phx.gbl>...
> > > > selection will identify what is selected.
> > > >
> > > > Perhaps if you said what you are really trying to do, someone could make a
> > > > suggestion. (as opposed to asking questions specific to how to implement
> > > > aspects of your creative solution which may not be the best way to attack
> > > > the problem). Also, since you are posting in comp.lang.visual.basic
> > > > perhaps if you mentioned where the code will be running - in excel or from a
> > > > vb app manipulating Excel with with automation or something else altogether.
> > > > --
> > > > Regards,
> > > > Tom Ogilvy
> > > >
> > > > "Andrew" <hooksie2@hotmail.com> wrote in message
> > > > news:9dfb6bbd.0409030532.678ce76e@posting.google.c om...
> > > > > Hi Bob,
> > > > > Thanks a lot for your explaination.
> > > > >
> > > > > I had thought maybe I could implement a stack to keep track of what
> > > > > object was currently active but from what you describe using a stack
> > > > > is more suited to procedures and even then of limited use since vba
> > > > > will return automatically to the previous procedure once finished.
> > > > >
> > > > > Is there any other way to identify the active object? In fact what I
> > > > > really want is the object prior to the active one. Kind of like
> > > > > Application.Caller but applicable to objects.
> > > > >
> > > > > In any case, thanks for your thoughts on stacks - it sheds some light
> > > > > on how a programming language may be working beneath the surface -
> > > > > interesting.
> > > > >
> > > > > Rgds,
> > > > > Andrew
> > > > >
> > > > >
> > > > > "Bob Kilmer" <rprgrmr@yahoo.com> wrote in message[/color]
> > news:<ep8wbqWkEHA.2500@TK2MSFTNGP09.phx.gbl>...[color=darkred]
> > > > > > Andrew,
> > > > > > I haven't done a lot of stack implementation, but my general[/color]
> > understanding[color=darkred]
> > > > > > is that one use of a stack is for storing procedure variables and memory
> > > > > > locations while processors call other procedures. All of the current
> > > > > > procedure variables get stuffed onto the stack to reserve their value,[/color]
> > along[color=darkred]
> > > > > > with the memory location to resume from, and the process continues[/color]
> > execution[color=darkred]
> > > > > > at the new memory location implied by the call. The new procedure may[/color]
> > itself[color=darkred]
> > > > > > call another procedure and store its info on the same stack, and so on.
> > > > > > Eventually the last procedure completes, returns control to the calling
> > > > > > procedure which pops its variables from the stack, eventually completes,
> > > > > > returns control, pops variables, etc. At least that is the myth I carry
> > > > > > around in my head. There are other uses for stacks, as in parsing[/color]
> > streams of[color=darkred]
> > > > > > input. I am sure you can find more academic explanations.
> > > > > >
> > > > > > I can envision using a VB Collection for a stack, which, as a practical
> > > > > > matter, would store VB objects in an order that could be controlled with
> > > > > > indexes. I write a lot of business and engineering software and I do not
> > > > > > remember implementing something I would really call a stack. Linked[/color]
> > lists,[color=darkred]
> > > > > > b-trees, arrays, other data structures, some may have been used like a[/color]
> > stack[color=darkred]
> > > > > > on a small scale. A stack is a pretty low level data type not often
> > > > > > encountered as such in modern business programming where the goal often[/color]
> > is[color=darkred]
> > > > > > patching together encapsulated data types (objects), data streams and[/color]
> > whole[color=darkred]
> > > > > > applications using higher level languages.
> > > > > >
> > > > > > My $0.02,
> > > > > > Bob
> > > > > >
> > > > > > "Andrew" <hooksie2@hotmail.com> wrote in message
> > > > > > news:9dfb6bbd.0409021606.6a1fa1de@posting.google.c om...
> > > > > > > Last night I was reading about implementing my own stack. The example
> > > > > > > given pushes items on and off the stack at the start and end of each
> > > > > > > procedure (ie. in a std module). What's not so clear is how this
> > > > > > > would work with class objects. In this case do you have to push the
> > > > > > > object on the stack at the start of every public procedure etc. in the
> > > > > > > class and pop it off at the end? I can't see how else you can know
> > > > > > > which object is active - or is this not normally a situation where a
> > > > > > > stack is employed?
> > > > > > >
> > > > > > > Thanks in advance,
> > > > > > > Andrew
> > >[/color][/color]
>[/color]