Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to implement a Stack 5

Status
Not open for further replies.

camjon

Technical User
Apr 2, 2008
17
US
I want to know if anyone knows how to implement a stack in vba
 
Gents,

I'm glad you've found the techniques useful. They're not exactly common or garden but they can really help in structuring your code for flexibility for the future. I can foresee a whole load of Access programs with lots of Undo functionality coming up soon!

If anyone would like to see a simple example of using Command pattern to get Undo functionality in VBA, let me know.

C

 
Craig,
I'd love to see it. I can't think of any useful scenarios yet, but I'm sure I will in the future!

Ben.

----------------------------------------------
Ben O'Hara
David W. Fenton said:
We could be confused in exactly the same way, but confusion might be like Nulls, and not comparable.
 
Contrived samples rule! TBH, most of my work is contrived, so should help loads!!

Cheers
B.


----------------------------------------------
Ben O'Hara
David W. Fenton said:
We could be confused in exactly the same way, but confusion might be like Nulls, and not comparable.
 
As soon as you save it, you notice an error!

Please substitute the code for LightOn and LightOff with

Code:
Private Sub LightOnButton_Click()

    Dim comm As Command
    Dim ctrl As Control
    
    Set comm = New LightOnCommand
    Set ctrl = Light
    
    comm.DoAction Null, ctrl
    undoStack.Push comm
    
    Command3.Enabled = True

End Sub

Private Sub LightOffButton_Click()

    Dim comm As Command
    Dim ctrl As Control
    
    Set comm = New LightOffCommand
    Set ctrl = Light
    
    comm.DoAction Null, ctrl
    undoStack.Push comm
    
    Command3.Enabled = true

End Sub

I forgot to enable the undo button.

Also.....in my rush to get this up, both

C
 
Blimey...I do get ahead of myself!

I meant to type

Each of the Command3.Enabled lines from the textboxes and Light command buttons can read Command3.Enabled = True. By definition, I know I have just pushed an item to the stack and therefore know the result of the IsEmpty test.

C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top