Results 1 to 4 of 4

Thread: [RESOLVED] Loop to add list box items

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    90

    Re: Loop to add list box items

    VB Code:
    1. Dim i As Integer
    2. Dim x As Integer
    3. i = List0.ListCount
    4. x = 0
    5. Do While Not x = i
    6. List1.AddItem List0.ItemData(x)
    7. x = x + 1
    8. Loop

    I got it too! Haha just saw your reply moinkhan.
    Your's definitely shorter. Any pros/cons besides length of code?
    Comments appreciated =P

    Astro

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: Loop to add list box items

    Quote Originally Posted by Astro
    VB Code:
    1. Dim i As Integer
    2. Dim x As Integer
    3. i = List0.ListCount
    4. x = 0
    5. Do While Not x = i
    6. List1.AddItem List0.ItemData(x)
    7. x = x + 1
    8. Loop

    I got it too! Haha just saw your reply moinkhan.
    Your's definitely shorter. Any pros/cons besides length of code?
    Comments appreciated =P

    Astro
    I dont know about any performance difference.. but as u can see.. the lower and upper bounds of loop are set at the start of loop.. it should be faster...
    This i know for sure.. Do While has to check the condition everytime...

    and... my coding style suggests that this job is for For..Next... Do While is for other complex conditions... for counter based loops.. use For..Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width