VB6 dynamic array definition

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 so it might need "redim" before it can be used? that is, I'm looking for something like:

if myarray is dynamic then
  redim ...
end if
myarray(x) = y

      

+1


a source to share


2 answers


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 -1 if empty.

+1


a source


Unfortunately there is nothing to tell if the array is dynamic. You could probably hack something together using specialized knowledge of the basic implementation of VB6 arrays, as in Matt Kurland's book.



I think the best approach is to use the function in this answer . It checks if the array is a dynamic array, which should be ReDimmed.

+1


a source







All Articles