Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 277757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:07:43+00:00 2026-05-12T01:07:43+00:00

What is the best way to determine the number of elements in an array

  • 0

What is the “best” way to determine the number of elements in an array in VBScript?

UBound() tells you how many slots have been allocated for the array, but not how many are filled–depending on the situation, those may or may not be the same numbers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T01:07:44+00:00Added an answer on May 12, 2026 at 1:07 am

    First off there is no predefined identifier called vbUndefined as the currently accepted answer appears to imply. That code only works when there is not an Option Explicit at the top of the script. If you are not yet using Option Explicit then start doing so, it will save you all manner of grief.

    The value you could use in place of vbUndefined is Empty, e.g.,:-

    If arr(x) = Empty Then ...
    

    Empty is a predefined identify and is the default value of a variable or array element that has not yet had a value assigned to it.

    However there is Gotcha to watch out for. The following statements all display true:-

    MsgBox 0 = Empty
    MsgBox "" = Empty
    MsgBox CDate("30 Dec 1899") = True
    

    Hence if you expect any of these values to be a valid defined value of an array element then comparing to Empty doesn’t cut it.

    If you really want to be sure that the element is truely “undefined” that is “empty” use the IsEmpty function:-

    If IsEmpty(arr(x)) Then
    

    IsEmpty will only return true if the parameter it actually properly Empty.

    There is also another issue, Null is a possible value that can be held in an array or variable. However:-

    MsgBox Null = Empty
    

    Is a runtime error, “invalid use of null” and :-

    MsgBox IsEmpty(Null)
    

    is false. So you need to decide if Null means undefined or is a valid value. If Null also means undefined you need your If statement to look like:-

     If IsEmpty(arr(x)) Or IsNull(arr(x)) Then ....
    

    You might be able to waive this if you know a Null will never be assigned into the array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

given any number, what's the best way to determine it is even? how many
what's the best way to determine whether a Javascript variable is an array, but
What's the best way to determine the first key in a possibly associative array?
What would be the best way to determine if an object equals number zero
What is the best way to determine how many window handles an application is
Given var x, what is the best way to determine if x can have
What is the best way to determine whether or not a field's value is
Please let me know what is the best way to determine composition of young
Possible Duplicate: In Java, what is the best way to determine the size of
What is the best way to programatically determine if a Perl script is executing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.