Results 1 to 13 of 13

Thread: getting the index of items in a listbox

  1. #1

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    getting the index of items in a listbox

    i go through the listbox using

    dim x as integer
    dim intIndex as integer
    for x = 0 to listbox.listcount
    intindex = listbox.list(x).index

    next x

    i recieve an error..
    i want to get the index of all the items in the listbox and put that in a variable as it goes throught the list... any ideas?

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Get the index? Please explain more...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  3. #3

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    reply..

    lets say i have 7 items in the listbox..

    as i loop through the listbox i am putting those 7 items into a file and i want along with that to put the associating index...

    strData & intIndex

    so the output would look like

    "MyData","4"

    so that I know the placement of that data in the listbox by the index.
    - gabe

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Just add in the x counter ?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  5. #5

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    yup

    thats what i tried but i get an error...


    For x = 0 To lstAlertLevels.ListCount
    intIndex = lstAlertLevels.List(x).Index
    Debug.Print lstAlertLevels(x).ListIndex
    Next x

  6. #6
    Addicted Member glyptar's Avatar
    Join Date
    Sep 2002
    Location
    The Netherlands
    Posts
    138
    For x = 0 To lstAlertLevels.ListCount -1
    intIndex = lstAlertLevels.List(x).Index
    Debug.Print lstAlertLevels(x).ListIndex
    Next x

    the highest index is listcount -1, since the 0 index is counted too.

    Hope it helps
    Glyptar

  7. #7
    Fanatic Member BillBoeBaggins's Avatar
    Join Date
    Jan 2003
    Location
    in your database, dropping your tables.
    Posts
    628
    Try this code, if your base is 0 then it can't go to ListCount because that be 1 more than existing.

    VB Code:
    1. dim x as integer
    2. dim intIndex as integer
    3. for x = 0 to listbox.listcount -1
    4. intindex = listbox.list(x).index
    5. next x
    (I love when I submit the same advice as someone else)

  8. #8
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    People, there is no such thing as lstAlertLevels.List(x).Index
    James ment:
    Code:
    For x = 0 To lstAlertLevels.ListCount -1 
    Debug.Print lstAlertLevels(x).ListIndex & "," & x
    Next x

  9. #9

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    error

    i recieve an error here...

    wrong number of arguments or invalid property assignment

    For x = 0 To lstAlertLevels.ListCount - 1
    Debug.Print lstAlertLevels(x).ListIndex & "," & x
    Next x

    lstAlertLevels is highlighted right after the debug.print...

  10. #10
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    wELL

    VB Code:
    1. For x = 0 To lstAlertLevels.ListCount - 1
    2. Debug.Print lstAlertLevels(x).lList & "," & x
    3. Next x
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  11. #11
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615

    Re: error

    Originally posted by gmatteson
    i recieve an error here...

    wrong number of arguments or invalid property assignment

    For x = 0 To lstAlertLevels.ListCount - 1
    Debug.Print lstAlertLevels(x).ListIndex & "," & x
    Next x

    lstAlertLevels is highlighted right after the debug.print...
    Sorry, didn't see that
    Try:
    Code:
    For x = 0 To lstAlertLevels.ListCount - 1
      Debug.Print lstAlertLevels.List(x) & "," & x
    Next x

  12. #12

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    haha

    i feel ashamed, too tired lol....

  13. #13
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    This code is correct.

    VB Code:
    1. For x = 0 To lstAlertLevels.ListCount - 1
    2.   Debug.Print lstAlertLevels.List(x) & "," & x
    3. Next x
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


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