By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

array notation

P: n/a
Hello,

I have an array declaration:

dim a(10) as string
To fill this array, I could use these lines:

a(0) = "x"
a(1) = "yy"
a(2) = "zzz"
....
but is there another notation instead of this to save some space?
Something like:

a = new array("x", "yy", "zzz", ...)
(offcourse the values "x", "yy", and "zzz", are simple examples)

Thanks,

Steven
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You need to declare and array and then if you want to limit it for example
to 3 items (0,1,2) you need to do a redim preserve
for example:
Dim strArr As String() = {"hallo", "hey", "hoi"}
ReDim Preserve strArr(2)

this isn't possible:
Dim strArr(2) as string = {"hallo,"hey","hoi"}

Hth Greetz Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.

"steven" <us**@example.net> schreef in bericht
news:uq**************@TK2MSFTNGP12.phx.gbl...
Hello,

I have an array declaration:

dim a(10) as string
To fill this array, I could use these lines:

a(0) = "x"
a(1) = "yy"
a(2) = "zzz"
...
but is there another notation instead of this to save some space?
Something like:

a = new array("x", "yy", "zzz", ...)
(offcourse the values "x", "yy", and "zzz", are simple examples)

Thanks,

Steven

Nov 21 '05 #2

P: n/a
"Peter Proost" <pp*****@nospam.hotmail.com> schrieb:
You need to declare and array and then if you want to limit it for example
to 3 items (0,1,2) you need to do a redim preserve
for example:
Dim strArr As String() = {"hallo", "hey", "hoi"}
ReDim Preserve strArr(2)


You can skip 'ReDim Preserve strArr(2)' because 'strArr' is already a string
array with three elements. When using the array initializer syntax the
compiler will set the upper bound automatically.

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

Nov 21 '05 #3

P: n/a
I didn't know that but I should have

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schreef in bericht
news:ed**************@TK2MSFTNGP10.phx.gbl...
"Peter Proost" <pp*****@nospam.hotmail.com> schrieb:
You need to declare and array and then if you want to limit it for example to 3 items (0,1,2) you need to do a redim preserve
for example:
Dim strArr As String() = {"hallo", "hey", "hoi"}
ReDim Preserve strArr(2)
You can skip 'ReDim Preserve strArr(2)' because 'strArr' is already a

string array with three elements. When using the array initializer syntax the
compiler will set the upper bound automatically.

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

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.