• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 141
  • Last Modified:

List Box

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.
0
anik
Asked:
anik
  • 4
  • 3
1 Solution
 
EyalCommented:
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
0
 
anikAuthor Commented:
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.
0
 
EyalCommented:
Use Add without the index 0
and the remove with the index 0
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
anikAuthor Commented:
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?
0
 
anikAuthor Commented:
Is it possible to make the new log append to the top of the list instead of the end of the list?
0
 
anikAuthor Commented:
Adjusted points to 65
0
 
EyalCommented:
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

0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now