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?

Thanking you in advance.

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?

> Thanking you in advance.

> 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  
 
 [ 3 post ] 

 Relevant Pages 

1. newbie question concerning if-then-else

2. DAO Question Concerning a Word Mail Merge from Access

3. ProjectResourceAdd concern/question

4. API Question Concerning Shell/Exec VB5.0

5. another question concerning data objects and combo boxes

6. another question concerning data objects and combo boxes

7. MTS; question concerning

8. MTS;questions concerning

9. Transaction Server; question concerning

10. Resultset Communication; questions concerning

11. Multi User Access Database - Questions/Concerns

12. Simple Question concerning Image Control in Database

 

 
Powered by phpBB® Forum Software