Example of MRU displaying in a combo box

Is there a way to find out the last 10 books I viewed like an MRU procedure in a combo box.

Examples are appreciated if it relates to combo box use much better
zachvaldezAsked:
Who is Participating?
 
JR2003Connect With a Mentor Commented:
The standard place to store this information for use next time is in the registry

In your form load and unload event you should have something like this:

Private Sub Form_Load()

    Dim i As Long
    Dim sBookName As String
   
    Combo1.Clear 'Initialsie
    For i = 1 To 10
        sBookName = GetSetting(App.Title, Me.Name, "MRUBook" & i, "")
        If sBookName <> "" Then
            Combo1.AddItem sBookName
        End If
    Next i

End Sub


Private Sub Form_Unload(Cancel As Integer)

    Dim i As Long
    Dim sBookName As String
    For i = 0 To Combo1.ListCount - 1
        sBookName = Combo1.List(i)
        SaveSetting App.Title, Me.Name, "MRUBook" & i + 1, sBookName
    Next i
    For i = Combo1.ListCount To 10
        SaveSetting App.Title, Me.Name, "MRUBook" & i + 1, ""  'Remove any old ones which may no longer be required
    Next i

End Sub
0
 
mladenoviczCommented:
You should have an array or collection that represents MRU. When you start app you should read it from file (txt, ini, xml, ...). When you open a book you should add it to the MRU. When you close app you should save MRU to the file. You can easy populate combo from array or collection
0
 
JR2003Commented:
See http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21101774.html
for something similar

As you use the combo when you add another item to the combo just do a check of Combo1.ListCount
If it's greater than 10 remove the 10th item (item 9)

    With Combo1
        If .ListCount > 10 Then
            .RemoveItem 9
        End If
    End With
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
zachvaldezAuthor Commented:
mladenovicz,
That may be a great idea. Please send me example code of your approach/recommendation.

Thanks
0
 
zachvaldezAuthor Commented:
I'd like to see an ex. to read and write to an ini or text file..The example JR2003 sent me was excellent but i'd like to save the values entered in the combo box in an ini  file/text file so I can retrieve it to know the last 10 MRU's items.

Thanks
0
 
JR2003Commented:
That last bit should have + 1 in it i.e.:

 For i = Combo1.ListCount + 1 To 10
        SaveSetting App.Title, Me.Name, "MRUBook" & i + 1, ""  'Remove any old ones which may no longer be required
    Next i
0
 
zachvaldezAuthor Commented:
Thanks again JR2003,
  I would like to know this time to how to display the 10 books from the registry in a notepad or text file.
Can I disply it in a text file so I can more or less confirm the top 10 are there/exist?
0
 
JR2003Commented:
Run regedit. (Go in to Start, Run then just type regedit)
 
Look under
HKEY_CURRENT_USER\Sotware\VB and VBA Program Settings

There should be a key under there which will be taken from your App.Title (e.g. Project1)
In there there's another key which is your form name (e.g. Form1)
In there are the MRUBook1...MRUBook10 values.
0
 
zachvaldezAuthor Commented:
While doing this anyhow, I still wanted to display more than 10 items in the listbox. So in order to differentiate the top ten MRUs,I'd prefer to highlight those items in the combo box to  to green> Is that possible? Thanks
0
 
JR2003Commented:
I don't think it's possible, perhaps you should start a new question on how to make items green in a listbox/combobox. You could use a ListView control and colour individual items though.

You can save more then 10 items in the registry, in fact you can save as many items as you like. Just adjust the  For loops in the code above:
 For i = 1 To ???

0
 
zachvaldezAuthor Commented:
That's great!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.