在VB6中,您可以静态和动态地声明一个数组。当动态声明一个数组时,是否可以确定该数组是否被声明为动态,因此在使用之前可能需要“redim”?即我正在寻找类似的东西:
if myarray is dynamic then
redim ...
end if
myarray(x) = y
答案 0 :(得分:1)
不幸的是,没有什么内在可以判断数组是否是动态的。你可以使用VB6数组底层实现的特殊知识来解决问题,就像Matt Curland的书一样。
我认为最好的方法是使用函数in this answer。它测试数组是否是需要ReDimmed的动态数组。
答案 1 :(得分:1)
使用此代码
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
(非ArrayName())如果为空则返回-1。