Solved

Example of MRU displaying in a combo box

Posted on 2004-08-23
11
200 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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
 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

776 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