Understanding automation : How is automation coding structured? : Using Boolean comparison and assignment |
In Microsoft Visual Basic (VB), Boolean comparison and Boolean assignment are both performed by using a single equals sign ( =
):
If a = b Then c = d |
By contrast, many other languages use a double equals sign for Boolean comparison and a single equals sign for Boolean assignment:
if( a == b ) c = d; |
The following code, which is valid in C, C++, Java, and JavaScript, is invalid in VBA:
if( ( result = fooBar( ) ) == true ) |
The preceding example would be written in VBA as the following:
result = fooBar( ) |
If result = True Then |
For other Boolean comparisons, VBA uses the same operators as other languages (except for the operators for is equal to and is not equal to). All the Boolean-comparison operators are provided in the following table.
Comparison
|
VBA operator
|
C-style operator
|
---|---|---|
Is equal to
|
=
|
==
|
Is not equal to
|
<>
|
!=
|
Is greater than
|
>
|
>
|
Is less than
|
<
|
<
|
Is greater than or equal to
|
>=
|
>=
|
Is less than or equal to
|
<=
|
<=
|
The result of using a Boolean operator is always either True
or False
.
Copyright 2013 Corel Corporation. All rights reserved.