473,671 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2 dimensional array question

I need to store information in a 2 dimensional array. I understand ArrayList
only works for a single dimensional array, is that correct ?
So, I use the 2 dimensional array like in VB6. I pass the array into a
subroutine, and inside it I "Redim Preserve" the array to increase the
number of item in the array. I got the error "Redim statement requires an
array", but arr is an array. HOw can I fix this problem ? Or, how can I do
ArrayList for 2 dimensional array ?
THank you very much.

Private arr(COM_MAX, 0) As String
LoadArr(arr)

Sub LoadArr(ByRef arr As Array)
lNumComm = 0
For x = 1 to 1000
ReDim Preserve arr(COM_MAX, lNumComm)--->Redim statement requires an array
:
next
Nov 20 '06 #1
6 2269
"fniles" <fn****@pfmail. comwrote in message
news:Ol******** *****@TK2MSFTNG P02.phx.gbl...
>I need to store information in a 2 dimensional array. I understand
ArrayList only works for a single dimensional array, is that correct ?
So, I use the 2 dimensional array like in VB6. I pass the array into a
subroutine, and inside it I "Redim Preserve" the array to increase the
number of item in the array. I got the error "Redim statement requires an
array", but arr is an array. HOw can I fix this problem ? Or, how can I do
ArrayList for 2 dimensional array ?
THank you very much.

Private arr(COM_MAX, 0) As String
LoadArr(arr)

Sub LoadArr(ByRef arr As Array)
Pass it in the same way you define the array, eg
Sub LoadArr(ByRef arr As int(,))
BTW, redim preserve does a complete copy of every element in the array every
time it's called. In your loop that will mean half a million copies for each
column.

Michael
Nov 20 '06 #2
Michael C is right about the Redim Preserve. I wouldn't do that.
I'd use an arraylist or a generic list (depending on what version
of .Net you're using.)

Robin S.
---------------------------------
"Michael C" <no****@nospam. comwrote in message
news:un******** ******@TK2MSFTN GP04.phx.gbl...
"fniles" <fn****@pfmail. comwrote in message
news:Ol******** *****@TK2MSFTNG P02.phx.gbl...
>>I need to store information in a 2 dimensional array. I understand
ArrayList only works for a single dimensional array, is that correct ?
So, I use the 2 dimensional array like in VB6. I pass the array into a
subroutine, and inside it I "Redim Preserve" the array to increase the
number of item in the array. I got the error "Redim statement requires an
array", but arr is an array. HOw can I fix this problem ? Or, how can I
do ArrayList for 2 dimensional array ?
THank you very much.

Private arr(COM_MAX, 0) As String
LoadArr(arr)

Sub LoadArr(ByRef arr As Array)

Pass it in the same way you define the array, eg
>Sub LoadArr(ByRef arr As int(,))

BTW, redim preserve does a complete copy of every element in the array
every time it's called. In your loop that will mean half a million copies
for each column.

Michael

Nov 21 '06 #3
"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:Lp******** *************** *******@comcast .com...
Michael C is right about the Redim Preserve. I wouldn't do that.
I'd use an arraylist or a generic list (depending on what version
of .Net you're using.)
Or redim at the start or redim at set intervals.

Michael
Nov 21 '06 #4
guy
why not have an Arraylist (or preferably a generic List(of T)) of Arraylists?

guy

"fniles" wrote:
I need to store information in a 2 dimensional array. I understand ArrayList
only works for a single dimensional array, is that correct ?
So, I use the 2 dimensional array like in VB6. I pass the array into a
subroutine, and inside it I "Redim Preserve" the array to increase the
number of item in the array. I got the error "Redim statement requires an
array", but arr is an array. HOw can I fix this problem ? Or, how can I do
ArrayList for 2 dimensional array ?
THank you very much.

Private arr(COM_MAX, 0) As String
LoadArr(arr)

Sub LoadArr(ByRef arr As Array)
lNumComm = 0
For x = 1 to 1000
ReDim Preserve arr(COM_MAX, lNumComm)--->Redim statement requires an array
:
next
Nov 21 '06 #5
Thank you everybody.
I would like to use ArrayList, but it does not work with 2 dimensional
array, does it ?
How can I have a 2 dimensional array ArrayList ?

"guy" <gu*@discussion s.microsoft.com wrote in message
news:78******** *************** ***********@mic rosoft.com...
why not have an Arraylist (or preferably a generic List(of T)) of
Arraylists?

guy

"fniles" wrote:
>I need to store information in a 2 dimensional array. I understand
ArrayList
only works for a single dimensional array, is that correct ?
So, I use the 2 dimensional array like in VB6. I pass the array into a
subroutine, and inside it I "Redim Preserve" the array to increase the
number of item in the array. I got the error "Redim statement requires an
array", but arr is an array. HOw can I fix this problem ? Or, how can I
do
ArrayList for 2 dimensional array ?
THank you very much.

Private arr(COM_MAX, 0) As String
LoadArr(arr)

Sub LoadArr(ByRef arr As Array)
lNumComm = 0
For x = 1 to 1000
ReDim Preserve arr(COM_MAX, lNumComm)--->Redim statement requires an
array
:
next

Nov 21 '06 #6
"fniles" <fn****@pfmail. comwrote in message
news:uD******** ******@TK2MSFTN GP06.phx.gbl...
Thank you everybody.
I would like to use ArrayList, but it does not work with 2 dimensional
array, does it ?
How can I have a 2 dimensional array ArrayList ?
You can put an array into each element of the arraylist I guess. Although
there is nothing wrong with using Redim Preserve if you limit it's use by
increasing the size of the array, say, every 1000 elements.

Michael
Nov 21 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2579
by: smurf | last post by:
Seems a simple question, but I can't find a simple answer: I have created a two dimensional array. I wish to send the data, a row at a time to a graph plotting routine which is expected a one dimension array. I could create a temporary one dimensional array and populate from the original array and then pass it to the routine, but this would seem to be long winded (read slow), and may well give me problems, as the previous values in the...
4
8176
by: Todd | last post by:
I'm new to c++ and was wondering how to sort a 2 dimensional array. I'm using a select sort for 1 dimensional arrays but it is not working for a 2 dimensional array. The 2 dimensional array are float elements. Thanks in advance
2
7661
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray = (data_type**)malloc(widht*height*sizeof(data_type)+ height* sizeof(data_type*)); //allocate individual addresses for row pointers. Now that I am moving to C++,am looking for something by which I can
6
2691
by: Ruben | last post by:
I'm trying to pass an array of string to a function without knowing how many strings I have beforehand. I've defined one functions as char * insert(char table,int cols, char values); out of deperation because when I defined it as char * insert(char table,int cols, char values)
4
3029
by: Balaskas Evaggelos | last post by:
Hi, does anyone know how i can sort a multi-dimensional array by a specific field ? for example i want to sort arr where n=2, but i need the data of every array to follow that order. example array: arr
8
11820
by: per9000 | last post by:
Hi all, I have a two-dimensional array of data, f.x int's. We can imagine that the array is "really large". Now I want the data in it and store this in a one-dimensional array. The obvious way to do this is a nested for-loop - but we all know O(n^2) is bad. So I am looking for something like ArrayList.ToArray(), or Matlabs A(:). C#
272
14012
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two dimensional arrays from std::vectors ??? I want to use normal Array Syntax.
5
3882
by: nelly0 | last post by:
developing a program that will manipulate noise levels (measured in decibels) that is collected by car manufacturers. These noise levels are produced at seven different speeds by a maximum of six different models of cars that are produced by the car manufacturer. Task 1 Step 1: Create a directory called Assignment02 and create the files of steps 2, 3 and 4 in this directory as well as your project file. Step 2: Create a file called...
152
9822
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { { 3.14 }, { 42.6 } }; f((double *)array, sizeof array / sizeof **array); return 0;
0
8476
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6229
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2812
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.