Results 1 to 4 of 4

Thread: Hip Hip Array

  1. #1
    Join Date
    Aug 2003
    Location
    UK
    Posts
    78

    Unanswered: Array

    Hello everyone,

    My problem: I want to put data into an array based on a listbox therefore the number of items in the array changes;

    MyCode start============================
    ‘put all the selected flights into an array
    For Each varItm In lstFlights.ItemsSelected
    iItem = iItem + 1
    Next varItm
    'dimention the array to hold the flights to book based on iitem
    ReDim Preserve garrFlightsSelected(iItem)
    For i = 1 To iItem
    'put data into the array
    garrFlightsSelected(i) = lstFlights.ItemData(i)
    MsgBox garrFlightsSelected(i) & " AND " & lstFlights.ItemData(i)
    Next i

    MYCode end ============================

    Question: Is there a better way to do this?

    Thanks Dap
    Last edited by dapman2002; 11-23-03 at 13:00.
    the light is on, someone is home, but they dont know they are. HELLO!

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    For Each varItm In lstFlights.ItemsSelected
    iItem = iItem + 1
    ReDim Preserve garrFlightsSelected(iItem)
    garrFlightsSelected(iItem) = lstFlights.ItemData(iItem)
    MsgBox garrFlightsSelected(iItem) & " AND " & lstFlights.ItemData(iItem)
    Next varItm

  3. #3
    Join Date
    Aug 2003
    Location
    UK
    Posts
    78
    Originally posted by CyberLynx
    For Each varItm In lstFlights.ItemsSelected
    iItem = iItem + 1
    ReDim Preserve garrFlightsSelected(iItem)
    garrFlightsSelected(iItem) = lstFlights.ItemData(iItem)
    MsgBox garrFlightsSelected(iItem) & " AND " & lstFlights.ItemData(iItem)
    Next varItm
    Thanks CyberLynx
    You got me on the right track but I had to change it because it would only give the first X number of items from the listbox. So I changed the lstFlights.ItemData(iItem) to lstFlights.ItemData(varItm) and thats done the trick..... Thanks.


    'count the number of items selected in the list and put them in a global variable
    giItem = lstFlights.ItemsSelected.Count
    'dimention the array to the size of iitem to hold the flights to book
    'based on flights selected in the listbox
    ReDim Preserve garrFlightsSelected(giItem)
    'put all the selected flights into an array
    For Each varItm In lstFlights.ItemsSelected
    garrFlightsSelected(i) = lstFlights.ItemData(varItm)
    Debug.Print garrFlightsSelected(i) & " " & lstFlights.ItemData(varItm)
    i = i + 1
    Next varItm
    the light is on, someone is home, but they dont know they are. HELLO!

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    Sorry... I just looked at your first posting and quickly rattled it off. I never tested it (sorry folks).

Posting Permissions

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