gpt4 book ai didi

arrays - Redim 没有 Dim?

转载 作者:行者123 更新时间:2023-12-04 23:59:08 26 4
gpt4 key购买 nike

我在 Win7 下使用 Access 2010。我发现我可以在运行时通过简单地调用 ReDim arrayName(x) 来确定我的数组的维度。无需先将数组声明为 Dim arrayName() .

Sub FooBar()
ReDim myArray(2)
myArray(0) = "This is the first string in myArray."
myArray(1) = "This is the second string in myArray."
myArray(2) = "And this is the last string in myArray."
MsgBox myArray(0) & vbCrLf & myArray(1) & vbCrLf & myArray(2)
End Sub

有什么理由我不应该使用这个快捷方式吗?

干杯!

最佳答案

那很有意思。 This MSDN page证实了你所看到的:这是一个引述:

"You can use the ReDim statement to declare an array implicitly within a procedure. Be careful not to misspell the name of the array when you use the ReDim statement. Even if the Option Explicit statement is included in the module, a second array will be created."



本页说明 Redim创建一个新数组并将现有数组复制到其中(假设有一个):

http://msdn.microsoft.com/en-us/library/w8k3cys2%28v=vs.80%29.aspx

至于您的问题,您是否应该这样做,我会说不,因为它令人困惑,并且确实将您的代码打开为 Option Explicit 无法捕获的错误。

有道理, Redim Preserve不会表现出这种行为。

关于arrays - Redim 没有 Dim?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12907050/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com