Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Subscript Out Of Range


Message #1 by jstmehr4u3@a... on Fri, 19 Apr 2002 18:53:25 +0000
How do you tell how many elements are in an array, so 
that you don't encount the error: "Subscript Out of 
Range"?


Is there such a thing as:
For Each ELEMENT in ARRAYX NEXT?

or:
for counter = 0 to ARRAYX(MAX NUMBER) where maxnumber is 
specified in a function somewhere? 

Thanks.
Message #2 by "Chris Thompson" <cthompson@n...> on Fri, 19 Apr 2002 14:34:25 -0600
Some objects have a ubound property

X =3D Obj.ubound

And for those that do not including arrays, use:

X =3D Ubound(arrayname)

Thanks,

Chris Thompson


-----Original Message-----
From: jstmehr4u3@a... [mailto:jstmehr4u3@a...]
Sent: Friday, April 19, 2002 12:53 PM
To: ASP Web HowTo
Subject: [asp_web_howto] Subscript Out Of Range

How do you tell how many elements are in an array, so
that you don't encount the error: "Subscript Out of
Range"?


Is there such a thing as:
For Each ELEMENT in ARRAYX NEXT?

or:
for counter =3D 0 to ARRAYX(MAX NUMBER) where maxnumber is
specified in a function somewhere?

Thanks.
Message #3 by Greg Griffiths <greg.griffiths@g...> on Fri, 19 Apr 2002 20:25:20 +0100
If you are dynamically populating an array using ReDims or have a fixed 
size array, then you can use UBound, otherwise  you'll have to use a 
variable as a value.

At 18:53 19/04/02 +0000, you wrote:
>How do you tell how many elements are in an array, so
>that you don't encount the error: "Subscript Out of
>Range"?
>
>
>Is there such a thing as:
>For Each ELEMENT in ARRAYX NEXT?
>
>or:
>for counter = 0 to ARRAYX(MAX NUMBER) where maxnumber is
>specified in a function somewhere?
>
>Thanks.
>
>
>---
>
>Improve your web design skills with these new books from Glasshaus.
>
>Usable Web Menus
>http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
>r-20
>Constructing Accessible Web Sites
>http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
>r-20
>Practical JavaScript for the Usable Web
>http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
>r-20


Message #4 by jstmehr4u3@a... on Fri, 19 Apr 2002 20:42:22 +0000
I am using the Split Function. LIke this:

SKUs = Split(SKULog,"|")

Now I need to know how many SKUs there were, and if I 
try and reference an array element that does not exist, 
I get the error.

Mike
Message #5 by "Chris Thompson" <cthompson@n...> on Fri, 19 Apr 2002 16:03:30 -0600
This will do it

Dim X as long
X =3D Ubound(SKUs)

I believe if you have a 10 space array meaning array(0) - array(9)
That it will return 10, but it could be 9.  Check to make sure.
Thanks,

Chris Thompson




-----Original Message-----
From: jstmehr4u3@a... [mailto:jstmehr4u3@a...]
Sent: Friday, April 19, 2002 2:42 PM
To: ASP Web HowTo
Subject: [asp_web_howto] RE: Sub Script out of Range

I am using the Split Function. LIke this:

SKUs =3D Split(SKULog,"|")

Now I need to know how many SKUs there were, and if I
try and reference an array element that does not exist,
I get the error.

Mike


---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogramm
e
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogramm
e
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogramm
e
r-20
Message #6 by "Ken Schaefer" <ken@a...> on Mon, 22 Apr 2002 12:34:49 +1000
Check the UBound() of the resulting array first.

<%
arrSKUs = Split(SKULog,"|")

If isArray(arrSKUs) then

    For i = 0 to UBound(arrSKUs)

        Response.Write(arrSKUs(i) & "<br>" & vbCrLf)

    Next

Else

    Response.Write("No array!")
    
End If
%>

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <jstmehr4u3@a...>
Subject: [asp_web_howto] RE: Sub Script out of Range


: I am using the Split Function. LIke this:
: 
: SKUs = Split(SKULog,"|")
: 
: Now I need to know how many SKUs there were, and if I 
: try and reference an array element that does not exist, 
: I get the error.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  Return to Index