Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Dynamic Arrays & subscript out of range error & a quick sql Q.


Message #1 by "David A. Fuller" <dfuller@m...> on Tue, 17 Apr 2001 16:27:48
I am a bit unclear on how Dynamic Arrays are handled. 



When I try to use one without declaring a fixed size for it before storing 

any information in the array it gives me a subscript out of range error.



If I declare the array of a fixed size it has no problems.



<%@ Language=VBScript %>

<% Option Explicit %>

<%

Dim MyArray(), Counter



Counter = 0



Do While Counter < 100

	  MyArray(Counter) = Counter

	  Response.Write "Counting up " & MyArray(Counter) & "<BR>"

	  Counter = Counter + 1

Loop

%>



The above code snippet would give me a subscript out of range error.  If I 

had declared MyArray as fixed, MyArray(100), it would work fine.



Is there something i'm doing wrong in declaring or implementing a dynamic 

array?



Does a dynanmic array have to be ReDimmed as a fixed before you can use it?



If so, whats the best/easiest way to get a count of all the records in a 

field of an SQL 7 Database so I can declare my array of that size before I 

start loading it with information?

Message #2 by =?iso-8859-1?Q?Fredrik_Norm=E9n?= <fredrik.normen@e...> on Wed, 18 Apr 2001 08:41:29 +0200
I'm back from the dead!



After declaring a dynamic array, use the ReDim statement within a procedure

to define the number of dimensions and elements in the array. If you try to

redeclare a dimension for an array variable whose size was explicitly

specified in a Private, Public, Protected or Dim statement, an error occurs.



/Fredrik Normén





-----Original Message-----

From: David A. Fuller [mailto:dfuller@m...]

Sent: den 17 april 2001 16:28

To: aspx_beginners

Subject: [aspx_beginners] Dynamic Arrays & subscript out of range error

& a quick sql Q.





I am a bit unclear on how Dynamic Arrays are handled.



When I try to use one without declaring a fixed size for it before storing

any information in the array it gives me a subscript out of range error.



If I declare the array of a fixed size it has no problems.



<%@ Language=VBScript %>

<% Option Explicit %>

<%

Dim MyArray(), Counter



Counter = 0



Do While Counter < 100

	  MyArray(Counter) = Counter

	  Response.Write "Counting up " & MyArray(Counter) & "<BR>"

	  Counter = Counter + 1

Loop

%>



The above code snippet would give me a subscript out of range error.  If I

had declared MyArray as fixed, MyArray(100), it would work fine.



Is there something i'm doing wrong in declaring or implementing a dynamic

array?



Does a dynanmic array have to be ReDimmed as a fixed before you can use it?



If so, whats the best/easiest way to get a count of all the records in a

field of an SQL 7 Database so I can declare my array of that size before I

start loading it with information?




  Return to Index