Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using UBound on empty array

Posted on 2004-10-13
5
Medium Priority
?
4,875 Views
Last Modified: 2007-12-19
I am doing something similar to the following:

Dim myArray()
...
'Some code that may ReDim myArray to some new size
...
If UBound(myArray) > 0 Then
...


If I make it to the line that checks UBound and nothing has yet been added to the array, I get the following error:

Microsoft VBScript runtime error '800a0009'

Subscript out of range: 'UBound'

How can I find out the size of my array when there is a possibility that the array may have no values?
0
Comment
Question by:steveo225
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Colosseo
ID: 12297798
Hi

you could try this as your first line

Dim myArray(0)

This should stop the error as the array has been dimensionalised (spelling :) )

Cheers

Scott
0
 
LVL 19

Accepted Solution

by:
peh803 earned 200 total points
ID: 12298056
Before you do ubound(myArray), do this:

if isArray(myArray) then
  if ubound(myArray)>0 then
     ''do whatever you want
  end if
else
  '' myArray isn't an array!
end if
0
 
LVL 4

Author Comment

by:steveo225
ID: 12298322
Scott, if I start the array at 0, when I try to ReDim it, I get this error:

Microsoft VBScript runtime error '800a000a'

This array is fixed or temporarily locked
0
 
LVL 4

Author Comment

by:steveo225
ID: 12298424
IsArray worked though, thanks peh
0
 
LVL 19

Expert Comment

by:peh803
ID: 12298665
glad to help!

peh803
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Loops Section Overview
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question