Solved

Easy List Box Question - Urgent

Posted on 2006-06-27
4
193 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
4 Comments
 
LVL 13

Accepted Solution

by:
jmundsack earned 125 total points
Comment Utility
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
Comment Utility
Dim i as integer 'better coding
For i = 0 To ListBox1.ListCount - 1
    '-- Your stuff--
Next i
0
 
LVL 2

Expert Comment

by:davidnsc1
Comment Utility
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
Comment Utility

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now