VBA中If Then行的最大长度 [英] Maximum length of an If Then line in VBA

查看:95
本文介绍了VBA中If Then行的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在包含诸如

之类的内容的行的VBA中是否有最大长度:

如果密码=" 1234"或密码=" 1235"或密码= ...............然后


在我看来,在某个阶段,我在

该行并不起作用。我假设它可能是255个字符,但

这条线的工作时间远远长于此。


dixie

解决方案

Dixie,


看来你必须有很多密码。假设你有一个名为

" MyForm"以及名为MyPassword的字段要输入密码,请考虑这样做:
这个:

建立一个名为TblPassword的表,并将所有密码放在名为
$ b $的字段中b密码。然后在你使用If语句的地方,改为使用它:


如果DCount(*,TblPassword,[密码] =''"& ;表格!MyForm!MyPassword&"''")

然后

<<不管怎么说,输入的密码都在列表中>> ;

Else

MsgBox"输入的密码不在列表中

结束如果

-

PC数据表

您的资源以获取Access,Excel和Word应用程序的帮助
re ****** @ pcdatasheet.com
www.pcdatasheet.com

" dixie" <二**** @ dogmail.com>在留言中写道

news:8j **************** @ nnrp1.ozemail.com.au ...

是包含以下内容的行的VBA中有一个最大长度:
如果密码=" 1234"或密码=" 1235"或密码= ...............然后

在我看来,在某个阶段,我在
结束时添加了一个额外的密码。线,它不起作用。我假设它可能是255个字符,但
有效的线路比这长得多。

dixie



dixie写道:

在包含类似
的内容的行的VBA中是否有最大长度:
如果密码=" 1234"或密码=" 1235"或密码=
...............然后

在我看来,在某个阶段,我在
行结束,它不起作用。我假设它可能是255个字符,但是工作的线路比这长得多。

dixie




它会使用Select Case构造更有效。这可能是你喜欢的任何长度,而且更具可读性。


例如


选择案例密码

Case Is =" 1234"

''在这里运行代码

Case Is =" 1235"

' '在这里运行代码

Case Is =" 1236"

''在这里运行代码

Case Is =" 1237"

''在这里运行代码


Case Is =" 1238"

''运行代码在这里

结束选择


On Mon,19 Jul 2004 07:52:08 +1000,dixie < di **** @ dogmail.com>

写道:


除非这是一个罕见的例外(但是你会指出那个

在你的帖子中),这听起来非常糟糕的应用程序设计。如果有人想要更改他或她的密码,他们就不得不问你要这么做吗?对我来说听起来像工作保障。

正如已经指出的那样,用户应该能够维护他们自己的密码,你可以将其存储(可能是加密的)

用户表。管理员应该能够重置密码。


或者,考虑用户已经登录到Windows,

你可以问Windows当前的用户名是什么

http:// www。 mvps.org/access/api/api0008.htm)。在大多数情况下,不需要进一步的

密码;用户能够在Windows中记录
这一事实证明她就是她所说的那样。


-Tom。

包含以下内容的行的VBA中是否有最大长度:
如果密码=" 1234"或密码=" 1235"或密码= ...............然后

在我看来,在某个阶段,我在
结束时添加了一个额外的密码。线,它不起作用。我假设它可能是255个字符,但
有效的线路比这长。

dixie




Is there a maximum length in VBA of a line containing stuff like the
following:
If password = "1234" or password = "1235" or password = ............... Then

It seems to me that at some stage, I add an extra password onto the end of
the line and it does not work. I assumed it might be 255 characters, but
the line that works is much longer than that.

dixie

解决方案

Dixie,

It seems you must have a lot of passwords. Assuming you have a form called
"MyForm" and a field named "MyPassword" to enter a password, consider doing
this:

Build a table called TblPassword and put all your passwords in a field named
Password. Then where you are using the If statement, use this instead:

If DCount("*","TblPassword","[Password] = ''" & Forms!MyForm!MyPassword & "''")
Then
<<Do whatever, the password that was entered is in the list>>
Else
MsgBox "The Password that was entered is not in the list"
End If
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"dixie" <di****@dogmail.com> wrote in message
news:8j****************@nnrp1.ozemail.com.au...

Is there a maximum length in VBA of a line containing stuff like the
following:
If password = "1234" or password = "1235" or password = ............... Then

It seems to me that at some stage, I add an extra password onto the end of
the line and it does not work. I assumed it might be 255 characters, but
the line that works is much longer than that.

dixie



dixie wrote:

Is there a maximum length in VBA of a line containing stuff like the
following:
If password = "1234" or password = "1235" or password =
............... Then

It seems to me that at some stage, I add an extra password onto the
end of the line and it does not work. I assumed it might be 255
characters, but the line that works is much longer than that.

dixie



It would be more efficient to use a Select Case construct. That could be
any length you like and alot more readable.

e.g

Select Case password
Case Is = "1234"
''run code here
Case Is = "1235"
''run code here
Case Is = "1236"
''run code here
Case Is = "1237"
''run code here

Case Is = "1238"
''run code here
End Select


On Mon, 19 Jul 2004 07:52:08 +1000, "dixie" <di****@dogmail.com>
wrote:

Unless this is a rare exception (but then you would have pointed that
out in your post), this sounds like very bad application design. If
someone wanted to change his or her password, they would have to ask
you to please do so? Sounds like job security to me.
Rather as was already pointed out, users should be able to maintain
their own password, which you would store (perhaps encrypted) in a
Users table. Administrators should be able to reset passwords.

Alternatively, consider that the user is already logged into Windows,
and you can ask Windows what the current username is
(http://www.mvps.org/access/api/api0008.htm). In most cases no further
password should be necessary; the fact that the user was able to log
into Windows is proof enough that she is who she says she is.

-Tom.

Is there a maximum length in VBA of a line containing stuff like the
following:
If password = "1234" or password = "1235" or password = ............... Then

It seems to me that at some stage, I add an extra password onto the end of
the line and it does not work. I assumed it might be 255 characters, but
the line that works is much longer than that.

dixie




这篇关于VBA中If Then行的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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