Results 1 to 6 of 6

Thread: Count indexes/items in a 2-Dimensional array, to ultimately populate a Listbox.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2009
    Posts
    64

    Count indexes/items in a 2-Dimensional array, to ultimately populate a Listbox.

    I'm trying to populate a ListBox on a main form with the values of a 2-dimensional array.

    This array will not have a known or fixed number of indexes or lines, so I need to count the indexes, to use this value in a loop to add each line Additem to a ListBox. I have not been able to find a similar enough post/example of counting the indexes to help.

    Simplified objective:
    Code:
    Dim Count as Byte
     Count = Disparray().IndexCount 'ie. 4 for 4 lines as below
       For x = 0 To Count  'Count = highest index value
         List1.AddItem Split(Disparray(x, x) at commas)  'I'm familiar with this 
       Next x
    Based on inputs to my app, array items will slowly come & go, so each time there is a change I want to refresh my Listbox based on current Disparray() contents.


    My array and array contents:
    Dim Disparray(0 To 10, 0 To 15) As String

    Data example
    1,3,Patient,Room,Treatment,Time_in
    3,7,Patient,Room,Treatment,Time_in
    3,9,Patient,Room,Treatment,Time_in
    4,5,Patient,Room,Treatment,Time_in

    Any suggestions appreciated
    Last edited by Enrique_; Aug 22nd, 2015 at 03:28 PM.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Count indexes/items in a 2-Dimensional array, to ultimately populate a Listbox.

    Is this for VB6? There is no IndexCount property for an array

    Using as an example: Dim Disparray(0 To 10, 0 To 15) As String
    UBound(Disparray,2) returns the upper bound of the 2nd dimension: 15
    UBound(Disparray,1) returns the upper bound of the 1st dimension: 10

    Does that help?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2009
    Posts
    64

    Re: Count indexes/items in a 2-Dimensional array, to ultimately populate a Listbox.

    Yes VB6.
    I know there isn't an index count, that was just to express my goal.

    I have looked at LBound and UBound but its doesn't help me identify which elements(?) of my array matrix contain data.

    I suppose I'll have to Loop read through the first dimension my entire array to find <> "" values, then post that string to the Listbox.

    Sorting would be another project.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Count indexes/items in a 2-Dimensional array, to ultimately populate a Listbox.

    Yes, there is no way to magically determine if the array item is anything other than an empty string.

    If you were to shift array contents each time a string was set to empty, then you could at least exit the looping early as blank strings are encountered. By shifting, I mean if you removed the 3rd item/index, then you would shift the 4th thru nth item down one in the array, aborting the shifting when an empty string encountered. This method obviously requires you to include overhead/management code when adding/removing strings from your array.

    Maybe a multidimensional array isn't the best storage option for your case?
    Last edited by LaVolpe; Aug 22nd, 2015 at 04:37 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2009
    Posts
    64

    Re: Count indexes/items in a 2-Dimensional array, to ultimately populate a Listbox.

    In an older version of my software I was writing the display items to an msaccess db table. That was then easy to refresh a display form's Listbox with active sorted events from a table. Since then I have moved many temporary items to arrays for much better speed. So I'll ponder for a few hours how to manage a 2-D array as if it were a db table.
    Last edited by Enrique_; Aug 22nd, 2015 at 04:47 PM.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Count indexes/items in a 2-Dimensional array, to ultimately populate a Listbox.

    Quote Originally Posted by Enrique_ View Post
    So I'll ponder for a few hours how to manage a 2-D array as if it were a db table.
    ADO disconnected recordset maybe?

    If sticking with an array, strongly recommend this if you aren't doing it already. Relating to a db table, size your 2D array as:
    ReDim Disparray(0 to nrFields-1, 0 to nrRecords-1). This way you can dynamically adjust the 2nd dimension as need arises and the 2nd dimension could return the actual 'record' count
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Tags for this Thread

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