Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
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…

688 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