Results 1 to 11 of 11

Thread: Classic VB - How do I check if array has been initialized?

Threaded View

  1. #3
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Re: Classic VB - How do I check if array has been initialized?

    Here's what I've used for a long time (I didn't know about the Merri method)

    VB Code:
    1. Public Type SafeArray1d
    2.     cDims As Integer
    3.     fFeatures As Integer
    4.     cbElements As Long
    5.     cLocks As Long
    6.     pvData As Long
    7.     cElements As Long
    8.     lLbound As Long
    9. End Type
    10.  
    11. Public Const ARRAY_NOT_INITIALISED As Long = -1
    12.  
    13. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, source As Any, ByVal Length As Long)
    14. Public Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Ptr() As Any) As Long
    15.  
    16.  
    17. Public Function MaxOrdinal(ppSA As Long) As Long
    18.    
    19.     ' Eg: n = MaxOridinal(VarPtrArray(MyArray))
    20.    
    21.     Dim SA As SafeArray1d
    22.     Dim pSA As Long
    23.  
    24.     '***********************************************
    25.     '* Deref ppSA. C equivalent: = pSa=*ppSA . . .
    26.     '***********************************************
    27.     CopyMemory pSA, ByVal ppSA, 4
    28.    
    29.     '*****************************************************
    30.     '* If we have a pointer then check to see how
    31.     '* many elements we are allowed. If the array
    32.     '* is not dimensioned then pSA will not be valid . . .
    33.     '*****************************************************
    34.     If pSA Then
    35.         CopyMemory SA, ByVal pSA, LenB(SA)
    36.         MaxOrdinal = (SA.cElements - 1)
    37.     Else
    38.         MaxOrdinal = ARRAY_NOT_INITIALISED
    39.     End If
    40.    
    41. End Function
    Last edited by si_the_geek; Jun 7th, 2006 at 07:37 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width