looping Through ListBox (VB6)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: looping Through ListBox (VB6)

  1. #1
    Join Date
    Jan 2006
    Posts
    5

    looping Through ListBox (VB6)

    I'm trying to get a loop to run through every line of my ListBox starting with the first one. What I've got so far runs through the lines but erases them when jumping to the next. Also I have tried for the loop to terminate at EOF using "Do Until EOF(1)" but it's returning an error.

    Any input is greatly appreciated; this is my code so far....

    Private Sub mnuFCMod_Click()
    Dim Item As String
    Dim i As Integer

    i = 0
    Do
    code...

    List1.List(i) = Item
    List1.Tag = i 'tag the number of file entries
    i = i + 1
    Loop
    End Sub

  2. #2
    Join Date
    Aug 2005
    Posts
    85

    Post

    It is difficult from your code snippet to know if what you have posted, represents everything. But here are my thoughts;

    Code:
    Dim Item As String
    Dim i As Integer
    
    i = 0
    Do
    code...
    
    List1.List(i) = Item
    List1.Tag = i 'tag the number of file entries
    i = i + 1
    Loop
    You Dim Item as a string but do not appear to set it to anything, so you are putting a blank string into the list.

    To iterate through the List try;

    Code:
    For i=0 to List1.listcount-1
        Item="Place something in this string"
        List1.list(i)=Item
    Next i
    
    List1.tag=List1.ListCount
    Edit:
    It occurs to me that what you may be after is to read each entry in the list that's already there;


    Code:
    Dim Item() As string
    For i=0 to List1.listcount-1
        Redim Preserve Item(i)
        Item(i)=List1.list(i)
    Next i
    
    List1.tag=List1.ListCount
    Steve.
    Last edited by Steve Grant; 01-18-2006 at 05:38 PM.

  3. #3
    Join Date
    Jan 2006
    Posts
    5

    looping through list

    Thanks Steve; works beautifully.

Similar Threads

  1. Speaking of strings...
    By Harlow in forum .NET
    Replies: 246
    Last Post: 10-26-2002, 01:30 AM
  2. Replies: 3
    Last Post: 07-21-2001, 03:32 PM
  3. vb6 crashes on a double click on a listbox
    By JT in forum VB Classic
    Replies: 2
    Last Post: 04-25-2000, 07:26 PM
  4. ListBox or ComboBox VB6
    By Fred Shoales fshoales in forum VB Classic
    Replies: 8
    Last Post: 03-30-2000, 06:44 PM
  5. ListBox or ComboBox VB6
    By Fred Shoales fshoales in forum VB Classic
    Replies: 0
    Last Post: 03-30-2000, 03:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center