Is Array Empty

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



according to google research there are at least 4 ways to test an array for
'emptiness' <g>
I suppose if you're in California, usa you could also spin a crystal over
it...but that's another story ....<g>

1 IsEmpty function (doesn't work...only tests for initialization, not
emptiness)
2 Ubound = -1 (doesn't work on uninitialized array because ubound
throws error)
3 api call using CopyMemory (in my test blows up ide instantly)
4 trap error on ubound call

here's the api version, posted here in past, that didn't work for me, maybe
it's not supposed to work in ide or some other problem????
also my stab at a general purpose function based on my tests of the above 4
ways...

comments welcome
Thanks
Mark


''note this crashes vb ide instantly in my tests
'janne paakkonen
'You can also put on your black belt and do some API-programming. The
'code below checks "under the hood" if the array's data pointer is
'initialized. Works for all arrays, all dimensions.
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(destination As Any, source As Any, ByVal lBytes As Long)
'Public Function IsArrayEmpty(vAnyArray As Variant) As Boolean
' Dim lAddressArrayDescriptor As Long
' Dim lAddressArrayData As Long
' CopyMemory lAddressArrayDescriptor, ByVal VarPtr(vAnyArray) + 8, 4
' CopyMemory lAddressArrayData, ByVal lAddressArrayDescriptor, 4
' IsArrayEmpty = IIf(lAddressArrayData = 0, True, False)
'End Function

'my attempt
Public Function IsArrayEmpty(vArr As Variant)
'if IsEmpty is going to work, use that
If IsEmpty(vArr) Then
IsArrayEmpty = True
Exit Function
End If

'trap error on uninitialized array
On Error Resume Next
Dim lUb As Long
lUb = UBound(vArr)
If Err Then
Err.Clear
IsArrayEmpty = True
Exit Function
End If
On Error GoTo 0

'if no error, is it negative
If UBound(vArr) = -1 Then
IsArrayEmpty = True
Exit Function
End If

End Function





.



Relevant Pages

  • Re: Is Array Empty
    ... ' Dim lAddressArrayDescriptor As Long ... IsArrayEmpty = True ... 'trap error on uninitialized array ...
    (microsoft.public.vb.general.discussion)
  • Re: Poor performance from file system
    ... moving several GB of music files from another machine or ... One consists of two IDE hard ... The other array consists of 4 SCSI drives, ...
    (comp.os.linux.misc)
  • Re: Poor performance from file system
    ... moving several GB of music files from another machine or ... One consists of two IDE hard ... The other array consists of 4 SCSI drives, ...
    (comp.os.linux.hardware)
  • Re: Variant array is empty problem
    ... The IsArrayEmpty function is one of about 25 array ... Public Function IsArrayEmpty(Arr As Variant) As Boolean ... Dim Var As Variant ...
    (microsoft.public.excel.programming)
  • Re: p5gd2premium ide detection problems
    ... My cd rom and dvd burner are on the ide ... > I have three sata hard drives on the raid sata ports. ... > I do have power to the two ide drives. ... Disks in array ...
    (alt.comp.periphs.mainboard.asus)