Solved

Using UBound on empty array

Posted on 2004-10-13
5
4,700 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
Comment Utility
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 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
IsArray worked though, thanks peh
0
 
LVL 19

Expert Comment

by:peh803
Comment Utility
glad to help!

peh803
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now