arrays - VBA 添加到 ReDim 值
问题描述
好的,所以我在使用 ReDim 数组时遇到了麻烦;有人告诉我这是这样做的方法。我只是不确定将它放在哪里,或者每次通过函数时都必须添加到第一个整数 ((n, n)) 中。仅供参考,“Dim PropArray(0, 5) As String”位于“选项比较数据库”所在的代码的最顶部。
Dim PropArray(0, 5) As String
Public Function ShowBeam()
For Each ctl In [Forms]![frmShelfBuilder]
If Left(ctl.Name, 3) = "Box" Then
If Int(Right(ctl.Name, (Len(ctl.Name)) - 3)) = Me.txtBeamCount Then
If Box1.Visible = False Then
Set rct = ctl
PropArray(0) = rct.Name
PropArray(1) = rct.Visible
PropArray(2) = rct.Height 'Int out
PropArray(3) = rct.Left 'Int out
PropArray(4) = rct.Top 'Int out
PropArray(5) = rct.Width 'Int out
Else
Set rct = ctl
'ReDim Preserve PropArray(n + 1, 5) where "n" is the current number in the row (I think this is were you would add the "ReDim Preserve"?)
PropArray(0) = rct.Name
PropArray(1) = rct.Visible
PropArray(2) = rct.Height 'Int out
PropArray(3) = rct.Left 'Int out
PropArray(4) = rct.Top 'Int out
PropArray(5) = rct.Width 'Int out
End If
End If
End If
Next
我认为我走在正确的轨道上。我只是不知道在哪里 ReDim 保留数组以将 1 添加到第一个整数。欢迎任何建议。Muchacho apreciado!
解决方案
如果你想能够做到ReDim
,那么你不能在Dim
将其更改为:
Dim PropArray() As String
ReDim PropArray(0, 5)
这将做同样的事情,并允许你ReDim Preserve
稍后再做。
注意:ReDim
正如您的代码所示,必须在例程内部而不是在例程外部。
所以像:
Dim PropArray() As String
Sub Prop_Init()
ReDim PropArray(0, 5)
End Sub
Sub Prop_AddDim()
ReDim Preserve PropArray(0, 6)
End Sub
另外请记住,您只能ReDim
访问数组的最后一部分。
推荐阅读
- vba - 保存在多选列表框中选择的记录
- vim - VIM 用 ~ 和 \r 查找和替换
- android - 当我在 gradle 文件中添加 UI Firestore 依赖项时,Android Studio 的地图活动中显示“无法访问 zzbfm”的错误
- javascript - 如何在反应中添加图像
- google-ads-api - 在 Google 数据洞察中创建新的计算字段 - 广告系列类型
- java - 发送特定的 POST 请求以接收 base64 格式的文本文件并在 WebView 中显示
- r - RDCOMClient + Outlook 电子邮件搜索使用 R 中的日期
- python-3.x - 处理 Tornado 的正确方法 read_bytes 方法
- c# - 尽管有 Console.ReadLine() 调用和更多代码,但 C# 控制台关闭
- xml - XSLT 匹配不同的条件