?
Solved

Easy List Box Question - Urgent

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

eg:

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

I do not know the correct syntax though..

Help
0
Comment
Question by:NAORC
[X]
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 Comments
 
LVL 13

Accepted Solution

by:
jmundsack earned 500 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
0
 
LVL 9

Expert Comment

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

Expert Comment

by:davidnsc1
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
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
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
Next

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 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.
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…
Suggested Courses

771 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