Skip to Content
VB.NET Language in a Nutshell, Second Edition
book

VB.NET Language in a Nutshell, Second Edition

by Steven Roman PhD, Ron Petrusha, Paul Lomax
April 2002
Intermediate to advanced
688 pages
19h 51m
English
O'Reilly Media, Inc.
Content preview from VB.NET Language in a Nutshell, Second Edition

Name

IsArray Function

Class

Microsoft.VisualBasic.Information

Syntax

IsArray(varname)
varname (required; any variable)

A variable that may be an array

Return Value

Boolean (True or False)

Description

Tests whether an object variable points to an array

Rules at a Glance

If the variable passed to IsArray is an array or contains an array, True is returned; otherwise, IsArray returns False.

Example

The following code displays True:

Dim s(  ) As Integer = {1, 2}
Dim t As Object
t = s
MsgBox(IsArray(t))

Programming Tips and Gotchas

  • Due to the nature of Objects, it is not always obvious if an Object variable contains an array, especially if you have passed the variable to a function and the function may or may not have attached an array to the variable. Calling the array function UBound or trying to access an element in an array that does not exist will generate an error. In these situations, you should first use the IsArray function to determine if you can safely process the array.

  • An uninitialized array returns False. For example:

    Dim strArr(  ) As String
    Console.WriteLine(IsArray(strArr))     ' Returns False
  • Array-like data structures, such as the Collection object, return False when passed to the IsArray function.

VB.NET/VB 6 Differences

In VB 6, the IsArray function returns True when passed an uninitialized array. In VB.NET, it returns False.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

VB .NET Language in a Nutshell

VB .NET Language in a Nutshell

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596003080Supplemental ContentCatalog PageErrata