473,324 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How to create 2 dimensional dynamic array (vb.net or c#)

I've tryed to something lik this and got "Object reference not set to
an instance of an object."

Dim myarr(,) As String
myarr(0, 0) = "aaaa"
myarr(0, 1) = "bbbb"
myarr(1, 0) = "cccc"
myarr(1, 1) = "dddd"

Thanks.

Apr 6 '07 #1
4 11188
>I've tryed to something lik this and got "Object reference not set to
>an instance of an object."

Dim myarr(,) As String
myarr(0, 0) = "aaaa"
myarr(0, 1) = "bbbb"
myarr(1, 0) = "cccc"
myarr(1, 1) = "dddd"

Thanks.

That's because you've only declared the variable, not made it refer to
an actual array object. Since you posted to the C# group, here's the
C# syntax

string[,] myarr = new string[2,2];

And if you use C#, the compiler will catch this error since you're not
allowed to use unassigned local variables.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 6 '07 #2
Hi,

array dimensions can't be changed, after the array is created. If you do not
know the exact size at the time you need to create the array, use ArrayList
instead.

In your case, using two dimensions, create a struct or class for the data
(time, value...) and add objects of it to an ArrayList.
Regards,
Husam Al-a'araj

"si*****@gmail.com" wrote:
I've tryed to something lik this and got "Object reference not set to
an instance of an object."

Dim myarr(,) As String
myarr(0, 0) = "aaaa"
myarr(0, 1) = "bbbb"
myarr(1, 0) = "cccc"
myarr(1, 1) = "dddd"

Thanks.

Apr 6 '07 #3
On Apr 6, 2:43 pm, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
I've tryed to something lik this and got "Object reference not set to
an instance of an object."
Dim myarr(,) As String
myarr(0, 0) = "aaaa"
myarr(0, 1) = "bbbb"
myarr(1, 0) = "cccc"
myarr(1, 1) = "dddd"
Thanks.

That's because you've only declared the variable, not made it refer to
an actual array object. Since you posted to the C# group, here's the
C# syntax

string[,] myarr = new string[2,2];

And if you use C#, the compiler will catch this error since you're not
allowed to use unassigned local variables.

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.
The problem I dont know how long will be this array, I cant define its
size.
I guess it cant be done with arrays, is there some control or type
that will do this job ?


Apr 6 '07 #4
The problem I dont know how long will be this array, I cant define its
size.
I guess it cant be done with arrays, is there some control or type
that will do this job ?
No problems with dynamic arrays.

Open source of strings (text file), get array dimensions m and n; then
create array:

string[,] myarr = new string[m, n];

And read strings to myarr.

Apr 6 '07 #5

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

Similar topics

2
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
11
by: fivelitermustang | last post by:
Actually, how would I go about allocating a four-dimensional dynamic array? I only know how to make two dimensional dynamic arrays: double **v; v = new double*; for (int i=0; i<C; i++) { v =...
10
by: BCC | last post by:
Ive been googling and reading through my books but I haven't figured out a solution (much less an elegant one) to create a multidimensional array with a runtime determined number of dimensions. I...
5
by: poojithareddy | last post by:
Hai, I am trying to pass a 2 dimensional array to a function and I am having a problem with this. If the array was a Static 2D array, the code would be somethinlike this void...
4
by: Bill Sun | last post by:
Hi, All I have a conventional question, How to create a 3 dimension array by C language. I see some declare like this: int *** array; int value; array = create3Darray(m,n,l);
60
by: Peter Olcott | last post by:
I need to know how to get the solution mentioned below to work. The solution is from gbayles Jan 29 2001, 12:50 pm, link is provided below: >...
2
by: =?Utf-8?B?SHVzYW0=?= | last post by:
Hi EveryBody: I am using vb.net 2005 and the following code trying to create varible at runtime: For n=1 to 4 dim v+n.tostring(n) as double Next n the resone behaind using the previous...
4
by: Sunny | last post by:
Hi, Is there a way in javascript to create Dynamic arrays or arrays on fly. Something Like: var "ptsgN"+sd = new Array(); Here sd is incrementing by 1. I have lots of data that I am...
1
by: ict027 | last post by:
i wanted to create a two dimensional dynamic array in vs.net . but it gives errors, this is the syntax i tried; Dim arrDen(,) As Integer(numOfEmp, nDen) i hope your suggestions to create...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.