Solved

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

Posted on 2003-10-29
3
219 Views
Last Modified: 2010-05-01
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
0
Comment
Question by:guidway
3 Comments
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 250 total points
ID: 9646832
0
 

Expert Comment

by:EmcoMaster
ID: 9647158
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


0
 
LVL 12

Author Comment

by:guidway
ID: 9650784
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question