Re: subscript out of range



You know, I don't have a big problem with an error handler in these cases
but I think the language would have benefited from an IsEmpty function that
worked on both arrays and collections. I still don't understand why
Microsoft avoided this functionality even in spite of my pleas during the
betas.

--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm

"Karl E. Peterson" <karl@xxxxxxxx> wrote in message
news:%23sBKWzQUFHA.1944@xxxxxxxxxxxxxxxxxxxxxxx
> Jonathan Wood wrote:
> >> There is, actually, by examining the SAFEARRAY descriptor:
> >
> > Sheesh, if that seems like a better approach to the OP than a simple
> > On Error Goto, I suggest he takes up C instead of VB. <gd&r>
>
> Isn't life funny sometimes? I needed to do this just today. Simple case.
VB6
> function that returns an array. Usually. Unless the input is invalid.
Well, I
> can't test Ubound() on the return. Adding an error trap would be "very
messy" in
> what's supposed to be fairly tight code here. So instead, I just whapped
this
> together (based on something I found on Randy's site):
>
> Public Function ArrayDimensions(arr As Variant) As Integer
> Dim lplpSafeArray As Long
> Dim lpSafeArray As Long
>
> ' Address of SafeArray pointer.
> Call CopyMemory(lplpSafeArray, ByVal VarPtr(arr) + 8&, ByVal 4&)
> If lplpSafeArray Then
>
> ' Address of the SafeArray structure
> Call CopyMemory(lpSafeArray, ByVal lplpSafeArray, ByVal 4&)
> If lpSafeArray Then
>
> ' First two bytes in SafeArray tell us the number of dims.
> Call CopyMemory(ArrayDimensions, ByVal lpSafeArray, 2&)
> End If
> End If
> End Function
>
> Public Function ArrayInitialized(arr As Variant) As Boolean
> ' If the array has 1 or more dims, it's initialized.
> ArrayInitialized = (ArrayDimensions(arr) > 0)
> End Function
>
> Seems to work. <g>
> --
> Working Without a .NET?
> http://classicvb.org/petition
>
>


.



Relevant Pages

  • Re: Detecting a running process.
    ... Private Declare Function EnumProcessModules Lib "psapi.dll" _ ... (ByVal dwProcessID As Long, _ ... Dim nProcesses As Long ... 'fill an array of longs with the ...
    (microsoft.public.vb.winapi)
  • Re: Updated datestamp doesnt work
    ... Public Sub StoreMyOldVals ... ' store values of current row in array ... Dim dbs As DAO.Database, rst As DAO.Recordset ... Dim var As Variant ...
    (microsoft.public.access.gettingstarted)
  • Re: Updated datestamp doesnt work
    ... Public Sub StoreMyOldVals ... ' store values of current row in array ... Dim dbs As DAO.Database, rst As DAO.Recordset ... Dim var As Variant ...
    (microsoft.public.access.gettingstarted)
  • Re: Updated datestamp doesnt work
    ... Public Sub StoreMyOldVals ... ' store values of current row in array ... Dim dbs As DAO.Database, rst As DAO.Recordset ... Dim var As Variant ...
    (microsoft.public.access.gettingstarted)
  • Re: Max/Min Functions
    ... You said the Array function won't work here. ... Dim myArray() As Variant ... > Dim vMax As Variant ...
    (microsoft.public.word.vba.general)