Re: subscript out of range
- From: "Jonathan Wood" <jwood@xxxxxxxxxxxxxxxx>
- Date: Thu, 5 May 2005 13:08:07 -0600
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
>
>
.
- Follow-Ups:
- Re: subscript out of range
- From: Karl E. Peterson
- Re: subscript out of range
- References:
- Re: subscript out of range
- From: Karl E. Peterson
- Re: subscript out of range
- Prev by Date: Re: VB and WinXP
- Next by Date: Re: subscript out of range
- Previous by thread: Re: subscript out of range
- Next by thread: Re: subscript out of range
- Index(es):
Relevant Pages
|