Visual Basic Helper Routines
Pure VB: Determine if an Array has been Dimensioned
Posted:   Wednesday June 2, 1999
Updated:   Monday December 26, 2011
Applies to:   VB4-32, VB5, VB6
Developed with:   VB6, Windows NT4
OS restrictions:   None
Author:   Bertie Wooster


CopyMemory: Determining Array Initialization State and Dimensions

Simple is Good. 

And so then is this function by Bertie Wooster that returns True when a passed array that has already been allocated space using Dim or ReDim, or False if unallocated. Just place the IsBounded() function into a form or module, declare Public or Private as appropriate, and pass as shown below.

 BAS Module Code
Place the following code into the general declarations area of a bas module:

Option Explicit
' Copyright 1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
Public Function IsBounded(vntArray As Variant) As Boolean

  'note: the application in the IDE will stop
  'at this line when first run if the IDE error
  'mode is not set to "Break on Unhandled Errors" 
  '(Tools/Options/General/Error Trapping)

   On Error Resume Next
   IsBounded = IsNumeric(UBound(vntArray))

End Function
 Form Code
To the form, add a command button and the following code:

Option Explicit

Private Sub Command1_Click()

   Dim x() As String
   Print IsBounded(x)
   Erase x
   ReDim x(5 To 6) As String
   Print IsBounded(x)
   Erase x
   ReDim x(0 To 5) As String
   Print IsBounded(x)
   Erase x
   ReDim x(5) As String
   Print IsBounded(x)

End Sub
The command code above will return :



PayPal Link
Make payments with PayPal - it's fast, free and secure!


Copyright 1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy


Hit Counter