|
-
Jul 6th, 2011, 10:52 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Ubound Check on MultiDimensional Array
Hello,
I've been searching around but can't seem to find this one.
I've got MultiDimensional Array and want to check the Ubound of each item lets say.
So:
Code:
Basket0.Apple0
Basket0.Apple1
Basket1.Apple0
Basket1.Apple1
Basket1.Apple2
Basket2.Apple0
Basket2.Apple1
UBound(Basket, 2) returns the apples but only for Basket0
How do you check how many apples Basket 2 has?
Thanks
Basket2.Apple2
Basket2.Apple3
Basket2.Apple4
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.

-
Jul 6th, 2011, 11:03 AM
#2
Re: Ubound Check on MultiDimensional Array
read this thread, may be useful.
-
Jul 6th, 2011, 11:16 AM
#3
Thread Starter
Frenzied Member
Re: Ubound Check on MultiDimensional Array
thanks but no, that still only gives the Ubound of each Dimension!
i.e
Ubound of Basket
Ubound of Apples
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.

-
Jul 6th, 2011, 11:22 AM
#4
Re: Ubound Check on MultiDimensional Array
Your array is really an array of UDTs, correct? Can you show us exactly what the Basketx are? That could be useful
Last edited by LaVolpe; Jul 6th, 2011 at 11:29 AM.
-
Jul 6th, 2011, 12:36 PM
#5
Re: Ubound Check on MultiDimensional Array
I don't see any evidence of an Array in the original code. I'd expect to see some brackets somewhere identifying the element(s) being assigned / read.
-
Jul 6th, 2011, 12:46 PM
#6
Re: Ubound Check on MultiDimensional Array
 Originally Posted by some1uk03
I've got MultiDimensional Array and want to check the Ubound of each item lets say.
So:
Code:
Basket0.Apple0
Basket0.Apple1
Basket1.Apple0
Basket1.Apple1
Basket1.Apple2
Basket2.Apple0
Basket2.Apple1
UBound(Basket, 2) returns the apples but only for Basket0
What value do you get using UBound(Basket, 2)?
What value would you hope to get for Basket1?
What value would you hope to get for Basket2?
Spoo
-
Jul 6th, 2011, 03:29 PM
#7
Thread Starter
Frenzied Member
Re: Ubound Check on MultiDimensional Array
yes the array is a UDT. so here in more detail:
Code:
Private Type myArray
fName As String
Apple As single
Banana As Single
Orange As Single
End Type
Private Basket() As myArray
Private Sub cmdPage_Click(Index As Integer)
'I know I could declare a fixed array length but want to dynamically increase it!!
ReDim Preserve Basket(10, 0) 'So we have 10 baskets
FillBank 0, "test", 121, 10, 0
FillBank 0, "test2", 121, 3, 0
FillBank 1, "test", 121, 10, 0
FillBank 1, "test2", 121, 3, 0
FillBank 1, "test3", 121, 3, 0
FillBank 1, "test4", 121, 3, 0
FillBank 2, "test", 121, 10, 0
''And this goes onnnnnn
End Sub
'Another Sub which fills the ARRAY
Private Sub FillBank(ByVal BankNo As Single, ByVal sName As String, ByVal CCNo As Single, ByVal CC3No As Single, ByVal ProgNo As Single)
Basket(BankNo, UBound(Basket, 2)).fName = CCNo
Basket(BankNo, UBound(Basket, 2)).Apple = CCNo
Basket(BankNo, UBound(Basket, 2)).Banana = CC3No
Basket(BankNo, UBound(Basket, 2)).Orange = ProgNo
ReDim Preserve Basket(bankNo, UBound(Basket, 2) + 1) 'open a buffer 1 ahead
End Sub
Ok so, as you can see..
1st I redim then array...
then I have another sub which fills the array...
So..
Basket(0) = should return 2
Basket(1) = should return 4
Basket(2) = should return 1
But I can only access Basket(0) with UBound(Basket, 2)
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.

-
Jul 6th, 2011, 03:42 PM
#8
Re: Ubound Check on MultiDimensional Array
 Originally Posted by some1uk03
...
But I can only access Basket(0) with UBound(Basket, 2)
Of course. When you dim Basket, it is (10,0). The 2nd dimension (UBound(Basket,2)) is zero and the 1st dimension (UBound(Basket,1)) will be 10.
What exactly are you trying to do? Also, is the sample code you posted your real code or fake code. If fake, please don't do that; let's see some real code.
-
Jul 6th, 2011, 04:01 PM
#9
Thread Starter
Frenzied Member
Re: Ubound Check on MultiDimensional Array
 Originally Posted by LaVolpe
Of course. When you dim Basket, it is (10,0). The 2nd dimension (UBound(Basket,2)) is zero and the 1st dimension (UBound(Basket,1)) will be 10.
yes, of course. But the question is; how do you get it to return how many entries basket(1) or basket(3) hold?
In simple english, I'm trying to get the count of entries UBOUND() of each BASKET?
So I'm literally looking for something like; UBound(Basket(1),2) or UBound(Basket(3),2)
and yes this is fake/simplified code... not 100% original... but does the job..
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.

-
Jul 6th, 2011, 04:48 PM
#10
Re: Ubound Check on MultiDimensional Array
I think redesign or looping thru your arrays are the answer. Regarding "does the job", not for me. I'm royally confused as your array and requirement doesn't make any sense to me I'm afraid.\
You have a 2D array of UDTs, doesn't matter if its UDTs strings, integers, whatever.
A 2D array is thought of like a table or Excel spreadsheet. In your case, you have 10 rows and 0 columns until you resize your array again and start to add columns. So the answer is always the same. The number of Baskets you have is [numElements1D]*[numElements2D]. In this case, it doesn't make a difference, if your array was initially a 1D array sized like Basket(10) which is initially identical to Basket(10,0) size-wise.
If you want to find out how many apples you have in each basket, you'll need to loop thru the array and count the apples member of each UDT in the array. If you want to know how many apples you have in Basket(10,0) then the answer is Basket(10,0).Apples and Basket(5,0).Apples for Basket(5,0)
Maybe looking at real code and/or better describing what you are trying to accomplish will help us?
-
Jul 6th, 2011, 05:02 PM
#11
Thread Starter
Frenzied Member
Re: Ubound Check on MultiDimensional Array
I think the options are to maybe create a Function to replace UBOUND() which loops @ each element and returns what I need.
Then again, taking the spreadsheet example: I can have 10 ROWS, but not each column will be filled? How do you return how many columns have data in them?
If you want to find out how many apples you have in each basket, you'll need to loop through the array and count the apples member of each UDT in the array
No, I need to find out how many ELEMENTS the array has, rather than the value of the UDT property.
To try and simplify this, I'm basically trying to AVOID having 10 separate arrays!
Private Basket1() as myArray
Private Basket2() as myArray
Private Basket3() as myArray
''etc.. etc...
So instead I want to use 1 Multidimensional one!
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.

-
Jul 6th, 2011, 05:30 PM
#12
Re: Ubound Check on MultiDimensional Array
If you want a variable 2D array, suggest something like this:
Code:
Private Type SubArrayStruct
fName As String
Apple As single
Banana As Single
Orange As Single
End Type
Private Type MyArray()
Count ' size of Items() array
Items() As SubArrayStruct
End Type
Private Basket() As myArray
Now Basket(0).Count can be a different size than Basket(1).Count. Therefore, the size of the array in Basket(0) can be different than Basket(1)
Not sure if that was what you were after
-
Jul 7th, 2011, 10:53 AM
#13
Thread Starter
Frenzied Member
Re: Ubound Check on MultiDimensional Array
 Originally Posted by LaVolpe
If you want a variable 2D array, suggest something like this:
Code:
Private Type SubArrayStruct
fName As String
Apple As single
Banana As Single
Orange As Single
End Type
Private Type MyArray()
Count ' size of Items() array
Items() As SubArrayStruct
End Type
Private Basket() As myArray
Now Basket(0).Count can be a different size than Basket(1).Count. Therefore, the size of the array in Basket(0) can be different than Basket(1)
Not sure if that was what you were after
Yea, this seems to do the job..
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.

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
|