List Box

Posted on 1998-09-28
Last Modified: 2010-04-30
I am writing a program that could show the error log on scrren by using listbox. I want to list only the last 20 log s and delete the rest of the logs that occur before. As listbox has the listcount property so that I can check if the data is more than 20 or not. The question is what is the best way to do this. I was thinking about changing the index to 0 and delete the content and copy the index 1 to 0 then copy index 2 to 1 and so on.. but there should be an easier and faster way.
Question by:anik
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
  • 4
  • 3
LVL 15

Expert Comment

ID: 1437194
you can enter the new list line to index 0:

List1.Add "The log text", 0

and after that remove the last entery of the list box if the ListCount is bigger then 20.

If List1.ListCount > 20 Then List1.RemoveItem 20

Author Comment

ID: 1437195
I tried it but the new line is not append at the end of log list. From your program the new line is place at index 0 and it's the top of the list. I just want every new log to be at the last line.
LVL 15

Accepted Solution

Eyal earned 60 total points
ID: 1437196
Use Add without the index 0
and the remove with the index 0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now


Author Comment

ID: 1437197
Thank you very much. I will also add another 10 points if you could explain me how this work. Is it remove the content in index 0 and add to index 0 again? Or it shift everything up and add the new content to index 5?

Author Comment

ID: 1437198
Is it possible to make the new log append to the top of the list instead of the end of the list?

Author Comment

ID: 1437199
Adjusted points to 65
LVL 15

Expert Comment

ID: 1437200
When you add an item you can add it anywhere on your list by specifying the index you want. If you ignore the Index parameter it will be added as the last item of the list.
The Remove method acts very similar to the Add method but without the item text.

Hope this helps
For more information see the VB online help of the Add Method


Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

617 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