IsArray Function


IsArray Function

Class

Microsoft.VisualBasic.Information

Syntax

     Dim result As Boolean = IsArray  (varName) 


varName (required; any variable)

A variable that may be an array

Description

The IsArray function indicates whether a variable is an array (true) or not (False).

Usage at a Glance

  • Due to the nature of .NET objects, it is not always obvious that an Object variable contains an array, since an entire array can be assigned to a simple Object variable. Calling array-specific functions like UBound or trying to access array elements on a variable that is not an array will generate an error. If there is doubt as to the nature of a variable, it should first be tested using the IsArray function.

  • An uninitialized array returns False. For example:

         Dim unusedArray(  ) As String     MsgBox(IsArray(unusedArray))     ' Displays "False" 

  • Array-like data structures, such as the Collection object, are not true arrays and return False when passed to the IsArray function.

Example

The following code displays "True," even though the Object variable was not initially declared as an array.

     Dim multipleData(  ) As Integer = {1, 2}     Dim singleData As Object     singleData = multipleData     MsgBox(IsArray(singleData))   ' Displays "True" 

Version Differences

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

See Also

Array Class




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net