Easy List Box Question - Urgent

Posted on 2006-06-27
Last Modified: 2010-04-30
In vb6 I want to do something to each individual item within a list box..


   for each item in listbox1.items
      'mess about with the contents of that line
   next item

I do not know the correct syntax though..

Question by:NAORC
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
LVL 13

Accepted Solution

jmundsack earned 125 total points
ID: 16994714
Dim i
For i = 0 To ListBox1.ListCount - 1
    MsgBox "The displayed item is " & ListBox1.List(i)
    MsgBox "The hidden, numeric value is " & ListBox1.ItemData(i)
Next i

Expert Comment

ID: 16996279
Dim i as integer 'better coding
For i = 0 To ListBox1.ListCount - 1
    '-- Your stuff--
Next i

Expert Comment

ID: 16996293
If you are going to be removing any, however, you're going to want to decrement i instead:
For i = ListBox1.ListCount - 1 to 0 step -1
LVL 13

Expert Comment

ID: 16997141

Private Sub Form_Load()
Dim i As Long        'even better coding, because a long is faster as an integer!
For i = 9 To 15      'first fill the list with random data
   List1.AddItem i

For i = 0 To List1.ListCount - 1
   List1.List(i) = "item: " & CStr(i)     'then assign new data
End Sub

Featured Post

Technology Partners: 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!

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

733 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