Solved

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

Posted on 2003-10-29
3
216 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now