Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access 如果(X和Y)>;访问VBA;0那么_Ms Access_Vba - Fatal编程技术网

Ms access 如果(X和Y)>;访问VBA;0那么

Ms access 如果(X和Y)>;访问VBA;0那么,ms-access,vba,Ms Access,Vba,我在这件事上被难住了。我在Access中有一些功能正常的VBA代码,如下所示 If (intFrontLoaded And 2) > 0 Then boolFrontLoad(1) = True Else boolFrontLoad(1) = False If (intFrontLoaded And 4) > 0 Then boolFrontLoad(2) = True Else boolFrontLoad(2) = False If (intFrontLoaded And 8) &

我在这件事上被难住了。我在Access中有一些功能正常的VBA代码,如下所示

If (intFrontLoaded And 2) > 0 Then boolFrontLoad(1) = True Else boolFrontLoad(1) = False
If (intFrontLoaded And 4) > 0 Then boolFrontLoad(2) = True Else boolFrontLoad(2) = False
If (intFrontLoaded And 8) > 0 Then boolFrontLoad(3) = True Else boolFrontLoad(3) = False
If (intFrontLoaded And 16) > 0 Then boolFrontLoad(4) = True Else boolFrontLoad(4) = False
If (intFrontLoaded And 32) > 0 Then boolFrontLoad(5) = True Else boolFrontLoad(5) = False
If (intFrontLoaded And 64) > 0 Then boolFrontLoad(6) = True Else boolFrontLoad(6) = False
我试图弄清楚
(intfrontload和X)>0)
是如何工作的

我知道它是做什么的,我想弄清楚它是如何做的,例如: 如果intFrontLoaded=14,则boolFrontLoad(1)、(2)和(3)将为真。 如果intFrontLoaded=28,则boolFrontLoad(2)、(3)和(4)将为真


我知道2+4+8=12和4+8+16=28,但是
(intFrontLoaded和X)>0
如何进行计算?

and运算符是一种逐位and运算-它比较每个操作数中的位,并返回两个操作数具有相同位的值

也就是说,您的代码将更清楚地写为:

boolFrontLoad(1) = (intFrontLoaded And 2) > 0
boolFrontLoad(2) = (intFrontLoaded And 4) > 0
boolFrontLoad(3) = (intFrontLoaded And 8) > 0
boolFrontLoad(4) = (intFrontLoaded And 16) > 0
boolFrontLoad(5) = (intFrontLoaded And 32) > 0
boolFrontLoad(6) = (intFrontLoaded And 64) > 0

运算符是一种逐位And运算-它比较每个操作数中的位,并返回两个操作数具有相同位的值

也就是说,您的代码将更清楚地写为:

boolFrontLoad(1) = (intFrontLoaded And 2) > 0
boolFrontLoad(2) = (intFrontLoaded And 4) > 0
boolFrontLoad(3) = (intFrontLoaded And 8) > 0
boolFrontLoad(4) = (intFrontLoaded And 16) > 0
boolFrontLoad(5) = (intFrontLoaded And 32) > 0
boolFrontLoad(6) = (intFrontLoaded And 64) > 0

在此上下文中是运算符。测试正在检查单个标志位。让我们使用
intFrontLoaded=14
If(intFrontLoaded和4)>0的例子,然后

14 as bitflags is this: 0000 0000 0000 1110
4 is this:              0000 0000 0000 0010
的结果是所有相同的位。在上面的示例中,只有“标志”位4。因此,
操作的结果是4

现在将其重新插入表达式:

If 4 > 0 Then
因此,它执行“true”条件。如果你注意到,所有的测试都是2的幂。这是因为当它们被表示为二进制时,它们只会是一个位

基本上,
intFrontLoaded
为被测试的每个位存储一个布尔值。这在早期的计算中更为常见,当时内存非常宝贵,使用所有16位存储布尔值被认为是浪费

请注意,您可以将其简化为:

boolFrontLoad(1) = intFrontLoaded And 2
boolFrontLoad(2) = intFrontLoaded And 4
boolFrontLoad(3) = intFrontLoaded And 8
boolFrontLoad(4) = intFrontLoaded And 16
boolFrontLoad(5) = intFrontLoaded And 32
boolFrontLoad(6) = intFrontLoaded And 64

在此上下文中是运算符。测试正在检查单个标志位。让我们使用
intFrontLoaded=14
If(intFrontLoaded和4)>0的例子,然后

14 as bitflags is this: 0000 0000 0000 1110
4 is this:              0000 0000 0000 0010
的结果是所有相同的位。在上面的示例中,只有“标志”位4。因此,
操作的结果是4

现在将其重新插入表达式:

If 4 > 0 Then
因此,它执行“true”条件。如果你注意到,所有的测试都是2的幂。这是因为当它们被表示为二进制时,它们只会是一个位

基本上,
intFrontLoaded
为被测试的每个位存储一个布尔值。这在早期的计算中更为常见,当时内存非常宝贵,使用所有16位存储布尔值被认为是浪费

请注意,您可以将其简化为:

boolFrontLoad(1) = intFrontLoaded And 2
boolFrontLoad(2) = intFrontLoaded And 4
boolFrontLoad(3) = intFrontLoaded And 8
boolFrontLoad(4) = intFrontLoaded And 16
boolFrontLoad(5) = intFrontLoaded And 32
boolFrontLoad(6) = intFrontLoaded And 64

这称为按位
操作。逻辑
intFrontLoaded和X
之间按位执行。当
X
是2的幂时,例如
2^a
,其二进制表示由零组成,除了(a+1)第位的1(从右到左编号位)

因此,
intFrontLoaded和4
检查是否设置了
intFrontLoaded
中的第三位。如果结果非零,则
if
将成功


在您的代码中,
intFrontLoaded
用作位集,即一组标志,其中每个位表示某个布尔条件的标志。

这称为
按位操作。逻辑
intFrontLoaded和X
之间按位执行。当
X
是2的幂时,例如
2^a
,其二进制表示由零组成,除了(a+1)第位的1(从右到左编号位)

因此,
intFrontLoaded和4
检查是否设置了
intFrontLoaded
中的第三位。如果结果非零,则
if
将成功

在代码中,
intfrontload
用作位集,即一组标志,其中每个位表示某个布尔条件的标志