Re: subscript out of range
- From: "Karl E. Peterson" <karl@xxxxxxxx>
- Date: Wed, 4 May 2005 17:53:30 -0700
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: Jonathan Wood
- Re: subscript out of range
- From: Rick Rothstein
- Re: subscript out of range
- From: Larry Serflaten
- Re: subscript out of range
- Prev by Date: Re: Can I activate desktop shortcut from macro?
- Next by Date: Re: Form Keydown events
- Previous by thread: Re: subscript out of range
- Next by thread: Re: subscript out of range
- Index(es):
Relevant Pages
|
Loading