views:

486

answers:

2

In VB6 you can declare an array statically and dynamically. When an array is declared dynamically, is it possible to determine if the array was declared dynamic and therefore would possibly need a "redim" before it can be used? i.e. I'm looking for something like:

if myarray is dynamic then
  redim ...
end if
myarray(x) = y
+1  A: 

Unfortunately there's nothing intrinsic to tell whether an array is dynamic. You could probably hack something together using special knowledge of the underlying implementation of VB6 arrays, as in Matt Curland's book.

I think the best approach is to use the function in this answer. It tests whether the array is a dynamic array that needs to be ReDimmed.

MarkJ
+1  A: 

Use this code

Private Sub Command1_Click()
    Dim A() As Double
    Dim B() As Double
    ReDim B(4)
    If (Not A()) = -1 Then MsgBox "Empty"
    If (Not B()) = -1 Then MsgBox "Empty"
End Sub

(Not ArrayName()) returns a -1 if it is empty.

RS Conley