Solved

Example of MRU displaying in a combo box

Posted on 2004-08-23
11
199 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:zachvaldez
  • 5
  • 5
11 Comments
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11872772
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
 
LVL 18

Expert Comment

by:JR2003
ID: 11872867
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
 

Author Comment

by:zachvaldez
ID: 11874341
mladenovicz,
That may be a great idea. Please send me example code of your approach/recommendation.

Thanks
0
 

Author Comment

by:zachvaldez
ID: 11874560
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
 
LVL 18

Accepted Solution

by:
JR2003 earned 100 total points
ID: 11875170
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 18

Expert Comment

by:JR2003
ID: 11875330
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
 

Author Comment

by:zachvaldez
ID: 11880918
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
 
LVL 18

Expert Comment

by:JR2003
ID: 11880999
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
 

Author Comment

by:zachvaldez
ID: 11881522
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
 
LVL 18

Expert Comment

by:JR2003
ID: 11881993
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
 

Author Comment

by:zachvaldez
ID: 11882405
That's great!!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

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

13 Experts available now in Live!

Get 1:1 Help Now