Class: HistoryList in Category General VBA/VB6 : Abstract Data Types from Total Visual SourceBook

Class that implements a history list in VBA and VB6.

If you have ever used a web browser, you are already familiar with the concept of a History List. When you press your browser's Back button, you return the previous page you viewed. Similarly, when you press the Next button, you move to the page after the one you are currently on.

This class implements the History List mechanism as a set of two stacks:

  1. Forward Stack - Contains items that have been popped off the history list.
  2. Backward Stack - Contains items that have been pushed onto the history list.

By maintaining these two stacks, the class keeps a history list that allows you to move back and forth through a history of items.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the CHistoryList class.
BackEnabled Property Determine whether Back should be enabled.
CurrentItem Property Get the current item from the history list.
ForwardEnabled Property Determine whether Forward should be enabled.
MaxItems Property Get the maximum number of items that can be added to the history list.
Class_Initialize Initialize Set initial values to defaults which may be overridden with property settings.
Add Method Add an item to the history list.
Back Method Move back in the history list.
EnumerateBack Method Enumerate the items available with the back method.
EnumerateForward Method Enumerate the items available with the forward method.
Forward Method Move forward in the history list.
GetItem Private Get an item in the history list.
' Example of CHistoryList
'
' To try this example, do the following:
' 1. Create a new form
' 2. Add a command button named 'cmdTest'
' 3. Paste all the code from this example to the new form's module
' 4. Run the form

Private HistoryList As CHistoryList

Private Sub cmdTest_Click()
  Dim varItem As Variant
  Dim varItems() As Variant

  ' Instantiate the History List variable
  Set HistoryList = New CHistoryList

  ' Override the standard MaxItems property to allow 10 items on the list
  HistoryList.MaxItems = 10

  HistoryList.Add "A"
  HistoryList.Add "B"
  HistoryList.Add "C"
  HistoryList.Add "D"
  HistoryList.Add "E"
  HistoryList.Add "F"

  HistoryList.Back
  HistoryList.Back
  HistoryList.Back

  Debug.Print HistoryList.CurrentItem

  HistoryList.Forward
  Debug.Print HistoryList.CurrentItem

  Debug.Print "Back Items: "
  HistoryList.EnumerateBack varItems
  For Each varItem In varItems
    Debug.Print varItem
  Next varItem

  Debug.Print "Forward Items: "
  HistoryList.EnumerateForward varItems
  For Each varItem In varItems
    Debug.Print varItem
  Next varItem

End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!


View all FMS products for Microsoft Access All Our Microsoft Access Products

Reviews

Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info

Question

 

 

Free Product Catalog from FMS