访问 VBA 更改大写 &随机小写 [英] Access VBA changes uppercase & lowercase randomly

查看:51
本文介绍了访问 VBA 更改大写 &随机小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MS Access 中有一个编码项目.有一些开发人员编码并将源代码签入到 SVN 服务器.由于 SVN-Server 用于管理代码,因此它可以识别源代码文件中的更改.在这些源代码文件中存在一个问题.VBA 经常改变大写和小写字母,我们不知道为什么.

I have a coding project in MS Access. There are some developers coding and checking in the source-code to a SVN-Server. As a SVN-Server is for managing code, it recognizes changes in the source-code files. In these source-code-files there is a problem. VBA often changes uppercase and lowercase letters and we have no clue why.

当我提交时就是

'two examples
Call myfunction(txtNodeID)
rst![Username] = Environ("USERNAME")

另一位开发人员更新了他的存储库并使用了我的代码,它更改为

Another developer updates his repository and uses my code and it changes to

'two examples
Call myfunction(txtNodeId)
rst![UserName] = Environ("USERNAME")

SVN 认为这是一个变化.所以我们有很多改变的文件,虽然逻辑没有改变,但Access修改了大写和小写.

SVN recognizes this as a change. So we have many changed files although the logic did not change but Access modified uppercase and lowercase.

有谁知道为什么 Access 会出现这种情况以及如何防止这种情况发生?

Does anyone know why Access is acting like this and how to prevent this?

谢谢.

推荐答案

VBA 编辑器应该强制变量名大小写与声明的变量名相同.这意味着,您应该无法编写以下内容:

The VBA editor should enforce variable name case to be the same as the declared variable name. This means, you should be unable to write the following:

Dim someID As String
someId = "5"

它对函数也有同样的作用.所以ENVIRON变成了Environ.

It does the same with functions. So ENVIRON becomes Environ.

但是,如果您不强制声明变量(顶部没有 Option Explicit),这会变得很奇怪.然后编辑器将很难知道哪种情况是正确,并且倾向于将所有内容更改为第一次出现.

However, this can get weird if you don't enforce variable declaration (no Option Explicit at the top). Then the editor will have a hard time knowing which is the correct case, and tend to change everything to the first occurrence.

解决方案是让所有开发人员都使用 Option Explicit,这样每个变量都被显式声明,VBA 编辑器知道哪种情况是正确的(并且还有许多其他优点).为了避免怪癖,他们还应该在保存之前使编辑过的行失去焦点(那是检查发生的时候,所以如果你真的想要,你可以做这个错误.如果你这样做,它可以更改为触摸时正确大小写).

The solution is to get all devs to use Option Explicit, so each variable is explicitly declared and the VBA editor knows which is the correct case (and there are many additional advantages). To avoid quirks, they should also make the edited line loses focus before saving (that's when the check happens, so you can do this wrong if you really want to. If you do, it can change to the correct case when touched).

这篇关于访问 VBA 更改大写 &随机小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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