烦人的VBA命名行为 [英] Annoying vba naming behaviour

查看:63
本文介绍了烦人的VBA命名行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Access 2007,这种行为可以复制如下.

I'm using access 2007 and this behaviour can be replicated as follows.

1)创建新的访问数据库accdb文件.
2)打开数据库并创建新的vba模块.
3)创建第一个子例程sub1:

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)创建第二个子例程sub2:

4) Create 2nd subroutine sub2:

Sub sub2(Description as String)
    Msgbox Description
End Sub

此时一切正常.
5)但是,如果我去更改sub2,以使描述"读为描述",即像这样将"D"更改为"d":

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

这也具有连锁效应,并且也更改了sub1!这样,sub1现在显示为:

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' ?

此行为似乎对代码的实际功能没有影响,因此没有问题.我遇到的最大问题是,我要将vba模块导出为文本文件,并将其置于SVN控制之下.正因为如此,最近才将全部毫无意义的更改"负载提交给存储库.

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?

推荐答案

对不起.那是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:

  1. 还原所有带有vba代码扩展名的已修改文件(创建备份.orig文件)
  2. 对.orig文件和其对应文件进行不区分大小写的比较
  3. 如果没有更改(大小写更改之外),请删除.orig文件
  4. 对于其余的.orig文件(具有实际更改的文件),请删除对应文件并删除.orig扩展名

这是有效地隐藏文件的唯一更改的文件(在您遇到问题时,使用VBA文件时经常出现的问题).它不会在进行了其他修改的文件中隐藏大小写更改.这不是一个完美的解决方案,但它是我想出的最好的解决方案.

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命名行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆