-
Aug 22nd, 2015, 02:49 PM
#1
Thread Starter
Lively Member
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.
-
Aug 22nd, 2015, 03:56 PM
#2
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?
-
Aug 22nd, 2015, 04:16 PM
#3
Thread Starter
Lively Member
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.
-
Aug 22nd, 2015, 04:23 PM
#4
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.
-
Aug 22nd, 2015, 04:43 PM
#5
Thread Starter
Lively Member
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.
-
Aug 22nd, 2015, 05:09 PM
#6
Re: Count indexes/items in a 2-Dimensional array, to ultimately populate a Listbox.
Originally Posted by Enrique_
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|