Using UBound on empty array

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?
LVL 4
steveo225Asked:
Who is Participating?
 
peh803Connect With a Mentor Commented:
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
 
ColosseoCommented:
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
 
steveo225Author Commented:
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
 
steveo225Author Commented:
IsArray worked though, thanks peh
0
 
peh803Commented:
glad to help!

peh803
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.