473,231 Members | 1,548 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,231 software developers and data experts.

Cant assign array values ! ? ! ?

I am so lost on this one.

Dim Ary as Integer = New Integer(4) {0,1,2,3}

FAILS with the error:
Array initializer has 1 too few elements.

So I try
Dim Ary as Integer = New Integer(3) {0,1,2,3}
Since arrays start at 0 (I am thinking)

and I get this error:
Value of type '1-dimensional array of Integer' cannot be converted to 'Integer'.

I can friggin assign values to the array AT ALL ?

What is wrong with this ?

So I guess the question is why dosent this work ?

How can I dimension and assign values ?

Chris
Nov 20 '05 #1
7 2690
If you want an array, you need to declare an array...
( note the () after the Ary )
Dim Ary() As Integer = New Integer(3) {0, 1, 2, 3}

For i As Integer = 0 To Ary.Length - 1

Trace.WriteLine(Ary(i).ToString())

Next
"Chris Wertman" <cw******@yahoo.com> wrote in message
news:14**************************@posting.google.c om...
I am so lost on this one.

Dim Ary as Integer = New Integer(4) {0,1,2,3}

FAILS with the error:
Array initializer has 1 too few elements.

So I try
Dim Ary as Integer = New Integer(3) {0,1,2,3}
Since arrays start at 0 (I am thinking)

and I get this error:
Value of type '1-dimensional array of Integer' cannot be converted to 'Integer'.
I can friggin assign values to the array AT ALL ?

What is wrong with this ?

So I guess the question is why dosent this work ?

How can I dimension and assign values ?

Chris

Nov 20 '05 #2
Yes, and when initializing, you don't have to specify the number of elements
in the array, thus
Dim Ary() As Integer = New Integer() {0, 1, 2, 3}
will work as well.

"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
If you want an array, you need to declare an array...
( note the () after the Ary )
Dim Ary() As Integer = New Integer(3) {0, 1, 2, 3}

For i As Integer = 0 To Ary.Length - 1

Trace.WriteLine(Ary(i).ToString())

Next
"Chris Wertman" <cw******@yahoo.com> wrote in message
news:14**************************@posting.google.c om...
I am so lost on this one.

Dim Ary as Integer = New Integer(4) {0,1,2,3}

FAILS with the error:
Array initializer has 1 too few elements.

So I try
Dim Ary as Integer = New Integer(3) {0,1,2,3}
Since arrays start at 0 (I am thinking)

and I get this error:
Value of type '1-dimensional array of Integer' cannot be converted to

'Integer'.

I can friggin assign values to the array AT ALL ?

What is wrong with this ?

So I guess the question is why dosent this work ?

How can I dimension and assign values ?

Chris


Nov 20 '05 #3
rdi
<you don't have to specify the number of elements in the array>

EXCEPT when you are not specifying the values at the time of creating the
array. In such a case you DO have specify the number of elements ahead of
time. Just something to keep in mind.

public sub test()
dim ary(0) as integer
ary(0) = 1

'to add another element--but this will overwrite previous elements
redim ary(1)
ary(1)=2

msgbox(ary(0).tostring +vbcrlf + ary(0).tostring) '<-this will display 0
even though you previously set it to 1

'set it back to 1
ary(0) = 1

'here we add another element while leaving the previous elements untouched.
redim preserve ary(2)
ary(2) = 3

msgbox(ary(0).tostring + vbcrlf + ary(1).tostring + vbcrlf +
ary(2).tostring)
end sub

--

RDI

(remove the exclamation from the email address)

"Chris Botha" <chris_s_botha@AT_h.o.t.m.a.i.l.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Yes, and when initializing, you don't have to specify the number of elements in the array, thus
Dim Ary() As Integer = New Integer() {0, 1, 2, 3}
will work as well.

"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
If you want an array, you need to declare an array...
( note the () after the Ary )
Dim Ary() As Integer = New Integer(3) {0, 1, 2, 3}

For i As Integer = 0 To Ary.Length - 1

Trace.WriteLine(Ary(i).ToString())

Next
"Chris Wertman" <cw******@yahoo.com> wrote in message
news:14**************************@posting.google.c om...
I am so lost on this one.

Dim Ary as Integer = New Integer(4) {0,1,2,3}

FAILS with the error:
Array initializer has 1 too few elements.

So I try
Dim Ary as Integer = New Integer(3) {0,1,2,3}
Since arrays start at 0 (I am thinking)

and I get this error:
Value of type '1-dimensional array of Integer' cannot be converted to

'Integer'.

I can friggin assign values to the array AT ALL ?

What is wrong with this ?

So I guess the question is why dosent this work ?

How can I dimension and assign values ?

Chris



Nov 20 '05 #4
That's what I said, "when initializing, you don't have to specify ...",
read my message.

"rdi" <rd**@writeme.com> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
<you don't have to specify the number of elements in the array>

EXCEPT when you are not specifying the values at the time of creating the
array. In such a case you DO have specify the number of elements ahead of
time. Just something to keep in mind.

public sub test()
dim ary(0) as integer
ary(0) = 1

'to add another element--but this will overwrite previous elements
redim ary(1)
ary(1)=2

msgbox(ary(0).tostring +vbcrlf + ary(0).tostring) '<-this will display 0
even though you previously set it to 1

'set it back to 1
ary(0) = 1

'here we add another element while leaving the previous elements untouched. redim preserve ary(2)
ary(2) = 3

msgbox(ary(0).tostring + vbcrlf + ary(1).tostring + vbcrlf +
ary(2).tostring)
end sub

--

RDI

(remove the exclamation from the email address)

"Chris Botha" <chris_s_botha@AT_h.o.t.m.a.i.l.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Yes, and when initializing, you don't have to specify the number of

elements
in the array, thus
Dim Ary() As Integer = New Integer() {0, 1, 2, 3}
will work as well.

"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
If you want an array, you need to declare an array...
( note the () after the Ary )
Dim Ary() As Integer = New Integer(3) {0, 1, 2, 3}

For i As Integer = 0 To Ary.Length - 1

Trace.WriteLine(Ary(i).ToString())

Next
"Chris Wertman" <cw******@yahoo.com> wrote in message
news:14**************************@posting.google.c om...
> I am so lost on this one.
>
> Dim Ary as Integer = New Integer(4) {0,1,2,3}
>
> FAILS with the error:
> Array initializer has 1 too few elements.
>
> So I try
> Dim Ary as Integer = New Integer(3) {0,1,2,3}
> Since arrays start at 0 (I am thinking)
>
> and I get this error:
> Value of type '1-dimensional array of Integer' cannot be converted to 'Integer'.
>
> I can friggin assign values to the array AT ALL ?
>
> What is wrong with this ?
>
> So I guess the question is why dosent this work ?
>
> How can I dimension and assign values ?
>
> Chris



Nov 20 '05 #5
Hi Chris

Dim Ary as Integer = New Integer(4) {0,1,2,3}


Dim Ary() as Integer = {0,1,2,3}

I hope this helps?

Cor
Nov 20 '05 #6
* cw******@yahoo.com (Chris Wertman) scripsit:
I am so lost on this one.

Dim Ary as Integer = New Integer(4) {0,1,2,3}

FAILS with the error:
Array initializer has 1 too few elements.

So I try
Dim Ary as Integer = New Integer(3) {0,1,2,3}
Since arrays start at 0 (I am thinking)

and I get this error:
Value of type '1-dimensional array of Integer' cannot be converted to 'Integer'.

I can friggin assign values to the array AT ALL ?

What is wrong with this ?


\\\
Dim i() As Integer = {1, 2, 3}
///

- or -

\\\
Dim i As Integer() = {1, 2, 3}
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7
rdi
I DID read your message and I didn't say you were wrong. The OP sounded
like he was new to arrays and I thought he might take
"you don't have to specify the number of elements in the array when
initializing, you don't have to specify" as meaning that he didn't need to
specify the number of arrays anymore.

I meant no offense to anyone and like I said, I wasn't trying to say that
you were wrong.
--

RDI

(remove the exclamation from the email address)

"Chris Botha" <chris_s_botha@AT_h.o.t.m.a.i.l.com> wrote in message
news:O7**************@TK2MSFTNGP09.phx.gbl...
That's what I said, "when initializing, you don't have to specify ...",
read my message.

"rdi" <rd**@writeme.com> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
<you don't have to specify the number of elements in the array>

EXCEPT when you are not specifying the values at the time of creating the
array. In such a case you DO have specify the number of elements ahead of time. Just something to keep in mind.

public sub test()
dim ary(0) as integer
ary(0) = 1

'to add another element--but this will overwrite previous elements
redim ary(1)
ary(1)=2

msgbox(ary(0).tostring +vbcrlf + ary(0).tostring) '<-this will display 0
even though you previously set it to 1

'set it back to 1
ary(0) = 1

'here we add another element while leaving the previous elements

untouched.
redim preserve ary(2)
ary(2) = 3

msgbox(ary(0).tostring + vbcrlf + ary(1).tostring + vbcrlf +
ary(2).tostring)
end sub

--

RDI

(remove the exclamation from the email address)

"Chris Botha" <chris_s_botha@AT_h.o.t.m.a.i.l.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Yes, and when initializing, you don't have to specify the number of

elements
in the array, thus
Dim Ary() As Integer = New Integer() {0, 1, 2, 3}
will work as well.

"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> If you want an array, you need to declare an array...
> ( note the () after the Ary )
> Dim Ary() As Integer = New Integer(3) {0, 1, 2, 3}
>
> For i As Integer = 0 To Ary.Length - 1
>
> Trace.WriteLine(Ary(i).ToString())
>
> Next
>
>
> "Chris Wertman" <cw******@yahoo.com> wrote in message
> news:14**************************@posting.google.c om...
> > I am so lost on this one.
> >
> > Dim Ary as Integer = New Integer(4) {0,1,2,3}
> >
> > FAILS with the error:
> > Array initializer has 1 too few elements.
> >
> > So I try
> > Dim Ary as Integer = New Integer(3) {0,1,2,3}
> > Since arrays start at 0 (I am thinking)
> >
> > and I get this error:
> > Value of type '1-dimensional array of Integer' cannot be converted

to > 'Integer'.
> >
> > I can friggin assign values to the array AT ALL ?
> >
> > What is wrong with this ?
> >
> > So I guess the question is why dosent this work ?
> >
> > How can I dimension and assign values ?
> >
> > Chris
>
>



Nov 20 '05 #8

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

Similar topics

5
by: Golf Nut | last post by:
I am finding that altering and affecting values in elements in multidimensional arrays is a huge pain in the ass. I cannot seem to find a consistent way to assign values to arrays. Foreach would...
6
by: Buddy Ackerman | last post by:
I created a simple class: Public Class MyTestClass Public Test() As String End Class I tried to assign some values to the array Test() and display them like this:
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
2
by: MLH | last post by:
Gentlemen: I have declared an array Dim MyTables(14) AS Long Now I want to assign values for MyTables(0) - MyTables(14) equal to the number of records in each table. Catch, I want the code...
26
by: Brett | last post by:
I have created a structure with five fields. I then create an array of this type of structure and place the structure into an array element. Say index one. I want to assign a value to field3 of...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
5
by: Ouwet5775 | last post by:
Hello peeps. Well i have tried runing the folwoing program several times, and i cant figure out what i am doing wrong. The goal of this is to input values for an array, find the maximum and the...
4
by: Avi | last post by:
Hi I am creating web application in which i want to assign by default values to the property which i had created my own. In that one of the property is of type color and i am unable to assign...
3
by: bharathi228 | last post by:
hi, how to assign a array as datasource to datagridview in vb.net. my problem is iam having an array with 60 values
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.