+ Reply to Thread
Results 1 to 12 of 12

Length of Array question

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,574

    Length of Array question

    I have a STRING array which is dimensioned with 100 elements possible. What i want to know is how to determine the "length" (not sure if this is the right word) of the array. For example: Suppose i have 10 strings in the array. Is there a command to determine that there are only 10 elements in the 100 possilble array?

  2. #2
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon welchs101
    Quote Originally Posted by welchs101 View Post
    I have a STRING array which is dimensioned with 100 elements possible. What i want to know is how to determine the "length" (not sure if this is the right word) of the array.
    You would have to loop through the array and test each string, and count at which point an empty string is returned.

    FWIW I think you're using arrays incorrectly. The idea is that if you don't know how big your array's going to be you set it up using empty parnetheses. Then everytime you add an element to the array you use Redim Preserve to re-dimension the array and keep the previous contents of the array unchanged :
    Please Login or Register  to view this content.
    The last UBound statement will return how many elements are in your array - you can change the value of 10 to anything - the array will always expand to accept the next value.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,574
    I had not thought of doing arrays in this fashion. Thanks.

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,574

    getting an error

    i tried what was suggested but i am getting an error.......subset of code is shown below:

    Please Login or Register  to view this content.



    error occurs on the ReDim statements..........

  5. #5
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,677
    Array must be dynamic when originally declared to be resized, e.g.,
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,574
    The array is declared as dynamic.

    Do you need the initial ReDim 1 to 20 statement?

  7. #7
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,677
    Nope. Just to illustrate.

  8. #8
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,574

    still get an error

    I think i tried the fix that you mentioned........here is the code now


    Please Login or Register  to view this content.


    it still gives me an error.......not sure why yet

  9. #9
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,574
    I tried you suggestion on a new blank program with nothing in it but the array and it worked.

    So it must be something i am doing.

    "The error i get is run-time error 10. The array is fixed or temporary locked"

  10. #10
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,677
    You haven't posted enough code to see what's causing the problem. Also, the code doesn't compile as-is; do you have public variables declared elsewhere?

  11. #11
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,574

    It works

    Thanks for your help. I went back and looked at some of my declarations and i found that i had actually NOT made dynamic the arrays that i thought i had made dynamic. I made them dynamic as you instructed and it worked. Thanks alot for you help.

    Sloppy coding on my part............

    thanks for your help!!!!!!!!!!!!!!!

  12. #12
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,677
    You're welcome. Good job sorting it out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1