Add to recent - Automatically create recent items
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).
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 namestr_name
and valuestr_data
Data(ByVal Index As Integer) As String
– return recent item data (value)Name(ByVal Index As Integer) As String
– return recent item nameLoadFile(ByVal str_file As String) As Boolean
– load recent items from file; if failed, returnfalse
RemoveItem(ByVal Index As Integer)
– delete recent itemSaveData(ByVal str_file As String)
– save recent items to fileSetMenu(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