none
How do I tell how many elements are in an array? RRS feed

  • Question

  • I am passed an array of strings and need to know how many elements are in the array so that I can use a For i = 0 to LengthOfArray. But I can't get the syntax or find the right methods in VBA, can anyone help?
    Monday, March 7, 2016 3:02 PM

Answers

  • I am passed an array of strings and need to know how many elements are in the array so that I can use a For i = 0 to LengthOfArray. But I can't get the syntax or find the right methods in VBA, can anyone help?

    Hi HTHP,

    You can use:  For i = 0 to UBound(<arraynaam>)

    Imb.

    • Marked as answer by HTHP Monday, March 7, 2016 5:16 PM
    Monday, March 7, 2016 3:29 PM

All replies

  • I am passed an array of strings and need to know how many elements are in the array so that I can use a For i = 0 to LengthOfArray. But I can't get the syntax or find the right methods in VBA, can anyone help?

    Hi HTHP,

    You can use:  For i = 0 to UBound(<arraynaam>)

    Imb.

    • Marked as answer by HTHP Monday, March 7, 2016 5:16 PM
    Monday, March 7, 2016 3:29 PM
  • Thanks!
    Monday, March 7, 2016 5:16 PM
  • you can use infinite length of array,so you can set or check array limit my  array.length
    Monday, March 7, 2016 5:19 PM
  • Followup question. How do I delete all the elements from an array in VBA? Man, this is an ancient language!
    Monday, March 7, 2016 5:48 PM
  • Followup question. How do I delete all the elements from an array in VBA? Man, this is an ancient language!

    Hi. You could loop through it, or the fastest way may be to use the ReDim statement. Just my 2 cents...

    PS. For example:

    ReDim ArrayName(UBound(ArrayName))

    Or:

    ReDim ArrayName(0)

    Hope that helps...

    • Edited by .theDBguy Monday, March 7, 2016 6:05 PM
    Monday, March 7, 2016 6:02 PM
  • Hi, HTHP

    This is the forum to discuss questions and feedback for Access for Developers, I'll move your question to the MSDN forum for Visual Basic for Applications (VBA)

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=isvvba

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents,
    and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.
     
    Thanks for your understanding.

    Tuesday, March 8, 2016 3:29 AM