Solved

Example of MRU displaying in a combo box

Posted on 2004-08-23
11
203 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

756 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