如何判断动态数组是否redim过

blp 2003-02-25 03:52:34
如何判断动态数组是否redim过
...全文
60 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
northwolves 2003-03-11
  • 打赏
  • 举报
回复
最近这个问题很多。其实动态数组可以用COLLECTION 代替:Dim x As New Collection
Private Sub Command1_Click()
x.Add "zx"
MsgBox x.Count
End Sub

Private Sub Command2_Click()
For i = 1 To 10
x.Add i * i
Next
MsgBox x.Count
End Sub

Private Sub Command3_Click()
Set x = Nothing
MsgBox x.Count
End Sub
freezx 2003-03-11
  • 打赏
  • 举报
回复
dim i%
i=0

redim a(5)
i=i+1

if i>0 then
msgbox "redim"
else
msgbox "no redim"
endif
night_cai 2003-03-11
  • 打赏
  • 举报
回复
可以记录是否用过。即定义个公用变量used为布尔型,在所有redim前加个变量used=True
龙华 2003-03-11
  • 打赏
  • 举报
回复
好帖。顶。
bigbigfans 2003-02-28
  • 打赏
  • 举报
回复
设一个变量,redim的时候设置为True,用类封装也是不错的啊,把redim过程重新封装,通过类的一个属性判断数组是否被Redim过。
为什么要知道数组是否被Redim过,是定义为 dim a() as long, 模式 , 判断它是否分配地址空间吗?
用户 昵称 2003-02-28
  • 打赏
  • 举报
回复
Option Explicit

Private Sub Command1_Click()
Dim a()
Debug.Print ismalloc(a)
ReDim a(10)
Debug.Print ismalloc(a)
End Sub

Private Function ismalloc(ByRef a()) As Boolean
On Error GoTo errhandle
Dim i As Integer
i = UBound(a)
ismalloc = True
Exit Function
errhandle:
Err.Clear
ismalloc = False
End Function
胖河马 2003-02-28
  • 打赏
  • 举报
回复
用Variant才行
Dim a As Variant
Debug.Print IsEmpty(a)
ReDim a(10)
Debug.Print IsEmpty(a)
ticsa 2003-02-25
  • 打赏
  • 举报
回复
试试这段代码,在网上找的
Option Explicit
Dim a() As Integer

Function IsDimed(b)
Dim c

On Error GoTo ErrHandle
c = UBound(b)
IsDimed = True
Exit Function
ErrHandle:
IsDimed = False
End Function

Private Sub Command1_Click()

On Error GoTo ErrHandle
MsgBox IsDimed(a())
Debug.Print 1 / 0
ReDim a(10) As Integer
MsgBox IsDimed(a())
Exit Sub
ErrHandle:
MsgBox "Oop!"
Resume Next
End Sub
zw_yu 2003-02-25
  • 打赏
  • 举报
回复
Dim lens As Integer
Dim a(5) As String

Private Sub Command1_Click()
ReDim a(10)
If lens <> UBound(a) Then
lens = UBound(a)
MsgBox "Changed!"
End If
End Sub

Private Sub Form_Load()
lens = UBound(a)
End Sub
XLYT 2003-02-25
  • 打赏
  • 举报
回复
有没有redim过很重要吗?
minajo21 2003-02-25
  • 打赏
  • 举报
回复
这个问题很尖端嘛
hehe

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧