Redim without Dim?

后端 未结 1 1275
孤街浪徒
孤街浪徒 2020-12-19 13:57

I\'m using Access 2010 under Win7. I\'ve discovered I can dimension my arrays at run-time by simply invoking ReDim arrayName(x) without first declaring the arr

相关标签:
1条回答
  • 2020-12-19 14:09

    That's interesting. This MSDN page confirms what you're seeing: Here's a quote:

    "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."

    This page explains that Redim creates a new array and that the existing array is copied into it (assuming there is one):

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

    As to your question, should you do it, I'd say no, because it's confusing, and does open your code to errors that Option Explicit won't catch.

    Reasonably enough, Redim Preserve doesn't exhibit this behavior.

    0 讨论(0)
提交回复
热议问题