Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using UBound on empty array

Posted on 2004-10-13
5
Medium Priority
?
4,838 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…

715 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