Link to home
Start Free TrialLog in
Avatar of guidway
guidwayFlag for United States of America

asked on

creating a most recently used (MRU) file list in the registry

I'm creating an application that needs to have a most recently used file list stored in the registry. When I load my application it will read the list for any values and place them into a listbox where the user will select what file they want to view. If the file the user loads is not recently used it will be pushed to the top of the list (up to 10 total). I'm having problems understanding how to implement such a feature since I'm not an expert on the registry (programmatically speaking).

Does anyone have some code that would work similar to this that might give me an idea of what to do?

I looked on the internet (I may have missed something) but didn't find anything very useful. I did find some things to help me create registry keys and delete them, but that is about it. Any help would be appreciated. Thanks

guid
ASKER CERTIFIED SOLUTION
Avatar of vinnyd79
vinnyd79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EmcoMaster
EmcoMaster

This will allow you to maintain a most recently used file list in the File...  menu.  It can be easily modified to use a list box though.  The registry calls will still be the same.


To update the mru list in the registry:
Call this sub when a file is opened, like this:

savemru(filename)

Then be sure to have this sub somewhere in the form or in a module:

Private Sub savemru(FName)
'Copy File 1 to File 2, File 2 to File 3, etc...
    For i = 9 To 1 Step -1
        keynum = "RecentFile" & i
        strFile = GetSetting("(your app name)", "MRU", keynum, "")
        If strFile <> "" Then
            keynum = "RecentFile" & (i + 1)
            SaveSetting "(your app name)", "MRU", keynum, strFile
        End If
    Next i
      ' add the current file as #1
    SaveSetting ")your app name)", "MRU", "RecentFile1", FName
End Sub

Then, in form1.load, add a call to the following sub call:

getmru

This will retrieve the MRU list from the registry and put it in the File... menu:

private sub getmru()
If GetSetting("(your application name", "MRU", "RecentFile1") = Empty Then Exit Sub
NumFiles = GetAllSettings("SFEditor", "MRU") ' NumFiles = number of files stored in registry
    For i = 1 To UBound(NumFiles, 1)            ' Add each file to the MRU list in the File... menu
        form1.mnuRecentFile(0).Visible = True
        form1.mnuRecentFile(i + 1).Caption = NumFiles(i, 1)
        form1.mnuRecentFile(i + 1).Visible = True
    Next i
end sub


Avatar of guidway

ASKER

believe it or not I looked at that link before and it looked like it only worked on the file menu. I didn't realize it also used the registry. lol thanks for the help!

guid