Solved

creating a 2d array

Posted on 2002-03-30
4
151 Views
Last Modified: 2010-05-02
Hi,
Easy question.  How do you create a dynamic 2D array?  And then how do you redim this array (what is the syntax)?
0
Comment
Question by:spandex44
  • 3
4 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 6907615
'Create dynamic array
dim intNum() as Integer

'Now use redim to make 2 dimensional
Redim intNum(1 to 3, 1 to 10)
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 75 total points
ID: 6907620
If you wish to resize the array and preserve the contents, use Redim Preserve.  For arrays with more than one dimension, you can only resize the final dimension, so do your planning carefully.

'Create dynamic array
dim intNum() as Integer

'Now use redim to make 2 dimensional
Redim intNum(1 to 3, 1 to 10)

intNum(1,1) = 5

'Resize final dimension...
Redim Preserve intNum(1 to 3, 1 to 20)
0
 

Author Comment

by:spandex44
ID: 6907772
SO how would you go about redimming the first dimension?
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6908184
You can redim the whole thing if you don't need to preserve the contents.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question