array notation

  • Thread starter Thread starter steven
  • Start date Start date
S

steven

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
 
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
 
Peter Proost said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top