烦人的 vba 命名行为
我使用的是 access 2007,可以按如下方式复制此行为。
1) 创建新的access数据库accdb文件。
2)打开数据库并创建新的vba模块。
3) 创建第一个子程序 sub1:
Sub sub1()
Msgbox Err.Description
End Sub
4) 创建第二个子程序 sub2:
Sub sub2(Description as String)
Msgbox Description
End Sub
此时一切正常。
5)但是,如果我去更改 sub2,使“Description”变为“description”,即将“D”更改为“d”,如下所示:
Sub sub2(description as String)
Msgbox description
End Sub
这也会产生连锁反应,并且也会更改 sub1!所以 sub1 现在显示为:
Sub sub1()
Msgbox Err.description
End Sub
为什么 'Err.Description' 更改为 'Err.description' ?
这种行为似乎对代码的实际功能没有影响,所以没有问题。我遇到的最大问题是我将 vba 模块导出为文本文件并将它们置于 SVN 控制之下。就在最近,大量毫无意义的“更改”已被提交到存储库中。
关于如何阻止这种情况发生有什么想法吗?
I'm using access 2007 and this behaviour can be replicated as follows.
1) Create new access database accdb file.
2) Open database and create new vba module.
3) Create 1st subroutine sub1:
Sub sub1()
Msgbox Err.Description
End Sub
4) Create 2nd subroutine sub2:
Sub sub2(Description as String)
Msgbox Description
End Sub
At this point everything is normal.
5) But if I go and change sub2 so that 'Description' reads 'description', i.e. change 'D' to 'd' like so:
Sub sub2(description as String)
Msgbox description
End Sub
This also has a knock-on effect and changes sub1 too! So that sub1 now reads:
Sub sub1()
Msgbox Err.description
End Sub
Why has 'Err.Description' changed to 'Err.description' ?
This behaviour seems to have no effect on the actual functionality of the code, so no problem there. The big issue I have is that I'm exporting my vba modules as text files and putting them under SVN control. And just recently a whole load of pointless 'changes' have been committed to the repository because of this.
Any ideas on how to stop this from happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对不起。这是 VBA 的硬编码“功能”。请参阅此处类似的问题:如何将默认情况恢复为 VBA (Excel 2010) 中的变量?
我使用源代码控制解决此问题的方法是通过执行以下操作的脚本运行我的存储库:
这样做的作用是有效隐藏仅更改大小写的文件(正如您遇到的那样,在使用 VBA 文件时这是一个持续存在的问题)。它不会隐藏已对其进行其他修改的文件中的大小写更改。它远非完美的解决方案,但它是我想出的最好的解决方案。
Sorry. That is a hard-coded "feature" of VBA. See similar question here: How does one restore default case to a variable in VBA (Excel 2010)?
The way I've worked around that with source control is to run my repository through a script that does the following:
What this does is effectively hide files where the only changes are to the case (a constant problem when working with VBA files, as you're experiencing). It does not hide case changes in a file that has had other modifications done to it. It's far from a perfect solution but it's the best I've come up with.
另外请记住,在 VBA 中,变量名不区分大小写。所以Description和description在同一范围内是相同的。
Additionally remember that in VBA, variable names are not case sensitive. So Description and description are the same within the same scope.