[英]What is the difference between True and msoTrue in VBA?
I am working on a model with some VBA code that hides/shows shapes:我正在研究一个带有一些隐藏/显示形状的 VBA 代码的模型:
Worksheets("Sheet1").Shapes("shape1").Visible = msoTrue
A previous developer used msoTrue throughout the model instead of True which is what I have typically used in this type of application.以前的开发人员在整个模型中使用 msoTrue,而不是我在此类应用程序中通常使用的 True。
I am trying to understand the difference between True and msoTrue, and wonder if I should be using one or the other.我试图了解 True 和 msoTrue 之间的区别,并想知道我是否应该使用其中一个。 I know that both equal -1.
我知道两者都等于-1。
msoTrue
is a constant that evaluates to -1. msoTrue
是一个计算结果为 -1 的常数。 In VBA it would be a Long
type.在 VBA 中,它将是
Long
类型。
True
is a Boolean
type. True
是Boolean
类型。 When converted to a Long
it also evaluates to -1.当转换为
Long
时,它的计算结果也为 -1。
Try this:尝试这个:
Debug.Print msoTrue '---> -1
Debug.Print True '---> True
Debug.Print Clng(True) '---> -1
It is somewhat odd to use msoTrue
instead of True
in a condition test, but -1, msoTrue
and True
will all be a true condition.在条件测试中使用
msoTrue
而不是True
有点奇怪,但是 -1、 msoTrue
和True
都将是一个真实的条件。
I should add that the Visibility
property of the Shape
object isn't a Boolean
type, it's a Long
of the enum msoTriState
.我应该补充一点,
Shape
对象的Visibility
属性不是Boolean
类型,它是枚举msoTriState
的Long
。 If your question relates specifically, and only, to Shapes
, then, yes, the more correct syntax would be msoTrue
.如果您的问题具体且仅与
Shapes
相关,那么,是的,更正确的语法是msoTrue
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.