Dozy question concerning arrays
Author Message
Dozy question concerning arrays

I'm sure I'm being thick but can someone tell me what I'm doing wrong:

Dim Avarray As Variant
Dim i As Integer

Avarray = Array(1020)

For i = 1 To 1000
Avarray(i) = i
Next

The first time through the loop Avarray(1) = 1 gives "Subscript out of
range". Am I using the wrong brackets?

Robert

Sun, 11 Jul 2004 22:35:00 GMT
Dozy question concerning arrays
Avarray=Array(1020) will create an array with 1 element; so all you have is
Avarray(0)=1020

What you want to do is

Dim Avarray As Variant
Dim i As Integer
ReDim Avarray(1 To 1020)
For i = 1 To 1000
Avarray(i) = i
Next

--
Robert Paquette

www.PaquetteSoftware.com

Quote:

> I'm sure I'm being thick but can someone tell me what I'm doing wrong:

>     Dim Avarray As Variant
>     Dim i As Integer

>     Avarray = Array(1020)

>     For i = 1 To 1000
>         Avarray(i) = i
>     Next

> The first time through the loop Avarray(1) = 1 gives "Subscript out of
> range". Am I using the wrong brackets?

> Robert

Sun, 11 Jul 2004 23:29:03 GMT
Dozy question concerning arrays

Robert

So I do. I live and learn. Thank you very much

Robert

Quote:

> Avarray=Array(1020) will create an array with 1 element; so all you
> have is Avarray(0)=1020

> What you want to do is

> Dim Avarray As Variant
> Dim i As Integer
> ReDim Avarray(1 To 1020)
> For i = 1 To 1000
>   Avarray(i) = i
> Next

> --
> Robert Paquette

> www.PaquetteSoftware.com

> > I'm sure I'm being thick but can someone tell me what I'm doing wrong:

> >     Dim Avarray As Variant
> >     Dim i As Integer

> >     Avarray = Array(1020)

> >     For i = 1 To 1000
> >         Avarray(i) = i
> >     Next

> > The first time through the loop Avarray(1) = 1 gives "Subscript out of
> > range". Am I using the wrong brackets?

> > Thanking you in advance.

> > Robert

Mon, 12 Jul 2004 01:05:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages