View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis Dana DeLouis is offline
external usenet poster
 
Posts: 947
Default Test Initialization of an Array

Hi Chip. This is just an fun observation. I can't add much, but thought
you might find this interesting.
Three negative numbers are assigned to each array, and are used again in
each loop.
However, the order in which they are assigned is in reverse order in which
they are erased.
In other words, in the code below, A is erased last, so it will be the first
one assigned in the next loop. All 3 outputs are the same in each loop.
However, if you erase them in order A, B, then C, then C will be allocated
first in the next loop. The 3 group of numbers will cycle back and forth.
Again, I don't know why either, but just an observation. :)

Sub Demo()
Dim A() As Long
Dim B() As String
Dim C() As Double
Dim j As Long

For j = 1 To 4
ReDim A(1 To 3)
ReDim B(1 To 3)
ReDim C(1 To 3)

Debug.Print Not A
Debug.Print Not B
Debug.Print Not C
Debug.Print "= = = = = "

Erase C
Erase B
Erase A
Next j
Debug.Print "= = = = = = = = = ="
End Sub

--
Dana DeLouis


"Chip Pearson" wrote in message
...
Neal,

Actually, there is another way to determine whether an array is actually
allocated, without using On Error. I don't use it for two reasons: (1) I
don't know why it works, and (2) it is probably unsupported by Microsoft.
However, it does work, just don't ask me why. I would be very wary of
using it in production code.

Dim A() As Long
If Not Not A Then
Debug.Print "allocated"
Else
Debug.Print "unallocated"
End If
ReDim A(1 To 3)
If Not Not A Then
Debug.Print "allocated"
Else
Debug.Print "unallocated"
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


<snip