Click here to Skip to main content
Click here to Skip to main content

Add to recent - Automatically create recent items

, 20 Oct 2007
Rate this:
Please Sign up or sign in to vote.
Automatically create recent menu items, it's very easy and useful. You just need to define file to save, and menu button (class will automatically create all items).

Screenshot - vb_recent.jpg

Introduction

This class automatically creates recent menu items. This class is very easy to use and is very useful. You only need to create a menu button (with index 0 to define a control array), define a file for saving recent items, and when you want, call the AddItem method. The class will automatically create all the menu buttons, delete the old buttons, set the button captions with item names, and button tag properties with item data values. You can also set the maximum count of recent items, and when you add items that already exist, the class will delete the old item and set the new items at the start (so it will be first on the list).

How to use

It is very easy to use this class. You just need to add this class to your project, define the maximum number of recent items (default is 5), create a menu button (with index 0 to define the control array), and that is all.

Functions / subs

  • AddItem(ByVal str_name As String, ByVal str_data As String) – insert new recent item with name str_name and value str_data
  • Data(ByVal Index As Integer) As String – return recent item data (value)
  • Name(ByVal Index As Integer) As String – return recent item name
  • LoadFile(ByVal str_file As String) As Boolean – load recent items from file; if failed, return false
  • RemoveItem(ByVal Index As Integer) – delete recent item
  • SaveData(ByVal str_file As String) – save recent items to file
  • SetMenu(ByRef objMenu As Object) – create menu items

Example (code for using recent items)

'show tag (data of recent item), button caption is
' recent item name
Private Sub buttRecent_Click(Index As Integer)
    MsgBox Me.buttRecent(Index).Tag
End Sub

'add new item to recent
Private Sub buttSave_Click()
    recent.AddItem Me.txtName.Text, Me.txtVal.Text
    recent.setMenu Me.buttRecent
End Sub

'load item on form load
Private Sub Form_Load()
    recent.MaxCount = 5 'number of recent items to display
    recent.LoadFile App.Path & "\rec.txt"
    'add items to control array buttRecent,
    ' class will do this (remove all items,and add new)
    recent.setMenu Me.buttRecent
End Sub

'save items to file on form terminate
Private Sub Form_Terminate()
    recent.SaveData App.Path & "\rec.txt"
    Set recent = Nothing
End Sub

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ivan0001

Croatia Croatia
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 20 Oct 2007
Article Copyright 2007 by Ivan0001
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid