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 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
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
<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
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
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
* 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/>
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 > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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:
|
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...
|
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...
|
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...
| |
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;
|
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...
|
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...
|
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
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |