Solved

Easy List Box Question - Urgent

Posted on 2006-06-27
4
196 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

791 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