Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-10-29
3
Medium Priority
?
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 1000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

610 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