Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

MRU for menus


Sub UpdateApplicationMRUList(FileName As String )
'maintain a list of the last n files opened in the program
'recreate menu list each time program is opened

'---------------------------
'put this in the combolist itemclick event
combolist1.additem FileName

'if it already exists in the list, then remove it
Dim i As Long , Found As Boolean , n As Long
n = 5

For i = 2 To n
  'check to see if FileName is already in the list
    If Lcase $(FileName) = Lcase $(mnuFileName(i).Caption) Then Found = True
Next i

If Found = False Then
   mnuFileName(5).Caption = mnuFileName(4).Caption
   mnuFileName(4).Caption = mnuFileName(3).Caption
   mnuFileName(3).Caption = mnuFileName(2).Caption
   mnuFileName(2).Caption = mnuFileName(1).Caption
   mnuFileName(1).Caption = X
End If


mnuSeparator36.Visible = False
For i = 1 To 5
   mnuFileName(i).Visible = Cbool (Len(Trim$(mnuFileName(i).Caption)))
    If mnuFileName(i).Visible = True Then mnuSeparator36.Visible = True
Next i

End Sub

'--------------------------- and run this at form load

mnuSeparator36.Visible = False
For i = 1 To 5
   mnuFileName(i).Visible = Cbool (Len(Trim$(mnuFileName(i).Caption)))
    If mnuFileName(i).Visible = True Then mnuSeparator36.Visible = True
Next i

'----------------------------  and use this to save/get settings between sessions

       mnuFileName(1).Caption = GetSetting(App.Title, "Settings" , "File1" , "" )
       mnuFileName(2).Caption = GetSetting(App.Title, "Settings" , "File2" , "" )
       mnuFileName(3).Caption = GetSetting(App.Title, "Settings" , "File3" , "" )
       mnuFileName(4).Caption = GetSetting(App.Title, "Settings" , "File4" , "" )
       mnuFileName(5).Caption = GetSetting(App.Title, "Settings" , "File5" , "" )

       SaveSetting App.Title, "Settings" , "File1" , mnuFileName(1).Caption
       SaveSetting App.Title, "Settings" , "File2" , mnuFileName(2).Caption
       SaveSetting App.Title, "Settings" , "File3" , mnuFileName(3).Caption
       SaveSetting App.Title, "Settings" , "File4" , mnuFileName(4).Caption
       SaveSetting App.Title, "Settings" , "File5" , mnuFileName(5).Caption