-
Not getting in the way of the UDT vs. Class discussion, but
1. Even tho you called it obj_MyType(), I think that it's still an array variable of MyType's, and not an object, so object-like tests (i.e. Is Nothing) probably won't work.
2. I've noticed a difference in behaviour if the array is declared outside the Sub vs. Inside. After the first run, it's Nothing, but for the second run, it remembers.
This is a little brute force, but at least you can tell that it's empty
[vba]
Option Explicit
Public Type MyType
x As Long
y As Long
z As Long
End Type
'if outside the sub, re-runs do not reset it to nothing
'Dim arr_MyType() As MyType
Sub MySub()
Dim i As Long
Dim arr_MyType() As MyType
'before
i = -1
On Error Resume Next
i = UBound(arr_MyType)
On Error Resume Next
If i = -1 Then
MsgBox "Nothing"
Else
MsgBox "There are " & (i + 1) & " entries"
End If
'put in some data 0 - 1
ReDim arr_MyType(1)
With arr_MyType(0)
.x = 1
.y = 2
.z = 3
End With
With arr_MyType(1)
.x = 1
.y = 2
.z = 3
End With
'after
i = -1
On Error Resume Next
i = UBound(arr_MyType)
On Error Resume Next
If i = -1 Then
MsgBox "Nothing"
Else
MsgBox "There are " & (i + 1) & " entries"
End If
End Sub
[/vba]
Paul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules