PC Review


Reply
Thread Tools Rate Thread

How do I declare and fill this array?

 
 
Ron
Guest
Posts: n/a
 
      7th Feb 2007
I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0

do I just do this:

Dim myarray as int = (5,7,8,9,0)

if not how would i do this?

thanks.

 
Reply With Quote
 
 
 
 
Michael Phillips, Jr.
Guest
Posts: n/a
 
      7th Feb 2007
Try this in VB.net:
Dim myarray As Integer() = {5,7,8,9,0}


"Ron" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0
>
> do I just do this:
>
> Dim myarray as int = (5,7,8,9,0)
>
> if not how would i do this?
>
> thanks.
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      7th Feb 2007
"Ron" <(E-Mail Removed)> schrieb:
>I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0
>
> do I just do this:
>
> Dim myarray as int = (5,7,8,9,0)
>
> if not how would i do this?


\\\
Dim MyArray() As Integer = {5, 7, 8, 9, 0}
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Reply With Quote
 
Doug Glancy
Guest
Posts: n/a
 
      7th Feb 2007
This makes me wonder, what's the difference between:

Dim MyArray() As Integer = {5, 7, 8, 9, 0}

and

Dim myarray As Integer() = {5,7,8,9,0}

thanks,

Doug

"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:uM8%(E-Mail Removed)...
> "Ron" <(E-Mail Removed)> schrieb:
>>I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0
>>
>> do I just do this:
>>
>> Dim myarray as int = (5,7,8,9,0)
>>
>> if not how would i do this?

>
> \\\
> Dim MyArray() As Integer = {5, 7, 8, 9, 0}
> ///
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      7th Feb 2007
"Doug Glancy" <(E-Mail Removed)> schrieb:
> This makes me wonder, what's the difference between:
>
> Dim MyArray() As Integer = {5, 7, 8, 9, 0}
>
> and
>
> Dim myarray As Integer() = {5,7,8,9,0}


There is no difference except in syntax.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Reply With Quote
 
Ray Cassick
Guest
Posts: n/a
 
      7th Feb 2007
One is correct and the other isn't

Dim MyArray() As Integer = {5, 7, 8, 9, 0} says exactly what you want. You
want an array of integer types.

Dim MyArray As Integer() = {5, 7, 8, 9, 0} really says that you want a
reference to an integer array.

While both will compile the second is a very ambiguous way to state what you
want.


"Doug Glancy" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> This makes me wonder, what's the difference between:
>
> Dim MyArray() As Integer = {5, 7, 8, 9, 0}
>
> and
>
> Dim myarray As Integer() = {5,7,8,9,0}
>
> thanks,
>
> Doug
>
> "Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
> news:uM8%(E-Mail Removed)...
>> "Ron" <(E-Mail Removed)> schrieb:
>>>I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0
>>>
>>> do I just do this:
>>>
>>> Dim myarray as int = (5,7,8,9,0)
>>>
>>> if not how would i do this?

>>
>> \\\
>> Dim MyArray() As Integer = {5, 7, 8, 9, 0}
>> ///
>>
>> --
>> M S Herfried K. Wagner
>> M V P <URL:http://dotnet.mvps.org/>
>> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

>
>



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      7th Feb 2007
Ray,

It is never good for a non native speaking English person to do a discussion
in that language.

But why is: "Create an object while giving it the name MyArray and use for
that an integer array" , not a more realistic way? (The myArray is just a
name, the array() tells the type to use and how many of those)

I have myself not any preference by the way, but telling that one is correct
and the other wrong is something I don't see using your explanation, even in
opposite of that.

Cor

"Ray Cassick" <rcassickNO-(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> One is correct and the other isn't
>
> Dim MyArray() As Integer = {5, 7, 8, 9, 0} says exactly what you want. You
> want an array of integer types.
>
> Dim MyArray As Integer() = {5, 7, 8, 9, 0} really says that you want a
> reference to an integer array.
>
> While both will compile the second is a very ambiguous way to state what
> you want.
>
>
> "Doug Glancy" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> This makes me wonder, what's the difference between:
>>
>> Dim MyArray() As Integer = {5, 7, 8, 9, 0}
>>
>> and
>>
>> Dim myarray As Integer() = {5,7,8,9,0}
>>
>> thanks,
>>
>> Doug
>>
>> "Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
>> news:uM8%(E-Mail Removed)...
>>> "Ron" <(E-Mail Removed)> schrieb:
>>>>I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0
>>>>
>>>> do I just do this:
>>>>
>>>> Dim myarray as int = (5,7,8,9,0)
>>>>
>>>> if not how would i do this?
>>>
>>> \\\
>>> Dim MyArray() As Integer = {5, 7, 8, 9, 0}
>>> ///
>>>
>>> --
>>> M S Herfried K. Wagner
>>> M V P <URL:http://dotnet.mvps.org/>
>>> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

>>
>>

>
>



 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      7th Feb 2007
"Ray Cassick" <rcassickNO-(E-Mail Removed)> schrieb
> One is correct and the other isn't
>
> Dim MyArray() As Integer = {5, 7, 8, 9, 0} says exactly what you
> want. You want an array of integer types.
>
> Dim MyArray As Integer() = {5, 7, 8, 9, 0} really says that you want
> a reference to an integer array.
>
> While both will compile the second is a very ambiguous way to state
> what you want.


The type of the variable is "integer array". The "()" (read: array) are part
of the type name. The variable type is put after the "As" keyword.
Consequently "As Integer()" (read: As Integer Array) makes more sense.

Armin
PS: There were already many discussions about ambiguous "()" (why are there
no "[]" for arrays like in C#?, why is it different if you specify an upper
bound?), so...

 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      7th Feb 2007
"Armin Zingler" <(E-Mail Removed)> schrieb:
>> One is correct and the other isn't
>>
>> Dim MyArray() As Integer = {5, 7, 8, 9, 0} says exactly what you
>> want. You want an array of integer types.
>>
>> Dim MyArray As Integer() = {5, 7, 8, 9, 0} really says that you want
>> a reference to an integer array.
>>
>> While both will compile the second is a very ambiguous way to state
>> what you want.

>
> The type of the variable is "integer array". The "()" (read: array) are
> part
> of the type name. The variable type is put after the "As" keyword.
> Consequently "As Integer()" (read: As Integer Array) makes more sense.


Well, I think that both declarations make sense, and I prefer the 'Dim
MyArray() As Integer' declaration for readability reasons (I think it's more
important that a variable contains an array than to read the type of its
items first).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

 
Reply With Quote
 
Tom Leylan
Guest
Posts: n/a
 
      8th Feb 2007
Oh good a trivial argument... you get so few of these on USENET :-) I'm
with Armin on this. If adding part of the variable's type definition onto
the variable name is a good idea then clearly syntax such as the following
would tell us that MyObject is a reference "before" having to see what it is
a reference to.

Dim MyObject* As Form

And as Armin intimates, if an IntegerArray keyword was defined nobody would
be questioning this at all.

Also Armin didn't actually "schrieb" what is stated in Herfried's reply.
The "One is correct and the other isn't " quote was written by "Ray
Cassick" <rcassickNO-(E-Mail Removed)> and while I note the grin in his
reply I will suggest that he is correct, he simply selected the wrong
example as the correct one :-) What you have is reference to an integer
array so why not declare it as such?


"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "Armin Zingler" <(E-Mail Removed)> schrieb:
>>> One is correct and the other isn't
>>>
>>> Dim MyArray() As Integer = {5, 7, 8, 9, 0} says exactly what you
>>> want. You want an array of integer types.
>>>
>>> Dim MyArray As Integer() = {5, 7, 8, 9, 0} really says that you want
>>> a reference to an integer array.
>>>
>>> While both will compile the second is a very ambiguous way to state
>>> what you want.

>>
>> The type of the variable is "integer array". The "()" (read: array) are
>> part
>> of the type name. The variable type is put after the "As" keyword.
>> Consequently "As Integer()" (read: As Integer Array) makes more sense.

>
> Well, I think that both declarations make sense, and I prefer the 'Dim
> MyArray() As Integer' declaration for readability reasons (I think it's
> more important that a variable contains an array than to read the type of
> its items first).



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declare Variables in Array Mike H. Microsoft Excel Misc 2 11th Mar 2009 12:33 PM
Declare array ranswert Microsoft Excel Programming 1 21st Mar 2008 02:34 PM
declare array with a default value? james Microsoft C# .NET 8 23rd Sep 2006 07:46 PM
How we can declare dynamic array in vb.net Himmat Solanki via .NET 247 Microsoft C# .NET 3 8th Mar 2005 06:56 AM
Declare an Array() ???? Andoni Microsoft Excel Programming 1 31st Aug 2004 07:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:01 PM.