473,508 Members | 2,206 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2699
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
6738
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
1723
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
25390
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
1830
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
7031
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
3755
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
1635
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
2493
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
27897
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
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7383
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...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
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...
0
1557
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 ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
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...

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.