By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

How to make a dynamic array with ReDim and Preserve?

P: 1
I was wondering how I can make an array that takes in integers, but have an endless array space so I don't have to limit my array in a for loop that ends in a large number
May 19 '15 #1
Share this Question
Share on Google+
1 Reply


Seth Schrock
Expert 2.5K+
P: 2,941
I would keep a global variable that stores the max subscript for your array. Each time that you need to add another element to the array, just increment that variable and then ReDim your array using the Preserve option.
Expand|Select|Wrap|Line Numbers
  1. intMAX_SUBSCRIPT += 1
  2. ReDim Preserve intMyArray(intMAX_SUBSCRIPT)
  3.  
  4. intMyArray(intMAX_SUBSCRIPT) = 15  'my new number
May 20 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.