Results 1 to 13 of 13

Thread: [RESOLVED] Ubound Check on MultiDimensional Array

  1. #1

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Resolved [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.



  2. #2
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: Ubound Check on MultiDimensional Array

    read this thread, may be useful.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  3. #3

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    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.



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

    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.
    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
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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.

  6. #6
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Ubound Check on MultiDimensional Array

    Quote Originally Posted by some1uk03 View Post
    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

  7. #7

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    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.



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

    Re: Ubound Check on MultiDimensional Array

    Quote Originally Posted by some1uk03 View Post
    ...
    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.
    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}

  9. #9

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Ubound Check on MultiDimensional Array

    Quote Originally Posted by LaVolpe View Post
    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.



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

    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?
    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}

  11. #11

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    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.



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

    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
    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}

  13. #13

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Ubound Check on MultiDimensional Array

    Quote Originally Posted by LaVolpe View Post
    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
  •  



Click Here to Expand Forum to Full Width