Array Concept Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What's the difference between the following 3 declaration methods. I am
really confused out here.

Dim date1 as Date()
Dim date1() as Date
Dim date1(10) as Date

Your expert advise is needed.
 
Nickson
Dim date1 as Date()
Dim date1() as Date
They are both the same, an empty array with is declared to hold Date values
Dim date1(10) as Date
An array which holds 10 date values which have nothing as value.

I hope this helps?

Cor
 
Chris Dunaway said:
Oops Cor! I know that you know this, but that line creates an
array of 11 date references (0-10). The dates have not been
created yet.

But there are actually no /references/ stored in the array... ;-).
 
Ok... I understand but when in my code I did this

Dim result() As String
result(0) = "test"

I get error but when I change the declaration to

Dim result(10) as String

the code works.

I impression on the first is that I have created a dynamic sized array that
automatically increase in size when more values are assigned? Am I wrong?


Chris Dunaway" <"dunawayc[[at]_lunchmeat said:
An array which holds 10 date values which have nothing as value.

Oops Cor! I know that you know this, but that line creates an array of 11
date references (0-10). The dates have not been created yet.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Nickson,

What you use is a fixed empty array what is not nice to use when it has to
increase.

When you want to add dynamicly to it you have to redimmension it using redim

However it is even stupid to show you because the arraylist is made for that
while this redimension of a fixed array is in my opinion a little bit for
backwards compatible use. The redim is not even in C#.

To make an arraylist is nothing more than
dim result as new arraylist
result.add("test")

And than "test" is
result(0) and because it is an object you have to tell when you use it
result(0).toString

I hope this helps?

Cor


Nickson Koh said:
Ok... I understand but when in my code I did this

Dim result() As String
result(0) = "test"

I get error but when I change the declaration to

Dim result(10) as String

the code works.

I impression on the first is that I have created a dynamic sized array
that
automatically increase in size when more values are assigned? Am I wrong?


Chris Dunaway" <"dunawayc[[at]_lunchmeat said:
Dim date1(10) as Date
An array which holds 10 date values which have nothing as value.

Oops Cor! I know that you know this, but that line creates an array of
11
date references (0-10). The dates have not been created yet.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Thx Cor.... The VB.NET array is now making more sense to me now : )


Cor Ligthert said:
Nickson,

What you use is a fixed empty array what is not nice to use when it has to
increase.

When you want to add dynamicly to it you have to redimmension it using redim

However it is even stupid to show you because the arraylist is made for that
while this redimension of a fixed array is in my opinion a little bit for
backwards compatible use. The redim is not even in C#.

To make an arraylist is nothing more than
dim result as new arraylist
result.add("test")

And than "test" is
result(0) and because it is an object you have to tell when you use it
result(0).toString

I hope this helps?

Cor


Nickson Koh said:
Ok... I understand but when in my code I did this

Dim result() As String
result(0) = "test"

I get error but when I change the declaration to

Dim result(10) as String

the code works.

I impression on the first is that I have created a dynamic sized array
that
automatically increase in size when more values are assigned? Am I wrong?


Chris Dunaway" <"dunawayc[[at]_lunchmeat said:
On Tue, 12 Oct 2004 07:57:05 +0200, Cor Ligthert wrote:


Dim date1(10) as Date
An array which holds 10 date values which have nothing as value.


Oops Cor! I know that you know this, but that line creates an array of
11
date references (0-10). The dates have not been created yet.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top