[AccessD] VBA Function with parameters

Stuart McLachlan stuart at lexacorp.com.pg
Sun Nov 7 17:07:56 CST 2021


Just dug up this little tutorial that I wrote a few years ago:

Boolean Algebra is the application of Boolean Logic to multiple bits.
The name  Boolean comes from the man man who invented Boolean Logic about 170 years 
ago - George Boole.

Boolean logic basically is a set of three rules which are applied to True and False states of 
two entities. 
It takes two True/False values (A and B) and deduce a true/false result (C) according to the 
operation performed on them.

AND operation: IF A and B are both true then C is true, otherwise it is false 
OR operation: IF either A or B is true then C is True
XOR operation: If exactly one of A and B are true then C is true.
It follows from the above three rules that if both values are false, the result of any of the 
three operations will be False.

In addition to these three operations there is a fourth operation which acts on a single value 
rather than a pair of values. NOT reverses the value of its parameter so NOT(True) = False 
and Not(False) = True.

As we have seen earlier, computer bit values of 1 and 0 can be thought of as True/False 
values. At a fundamental level, computer circuits work by taking bits in two memory 
locations and applying Boolean Logic to pairs of bits to determine new bit values. A modern 
computer will perform this "bit switching" billions of times per second on 32 or 64 bits at a 
time. (That's what is meant by 32 bit and 64 bit operating sysems :))

Are you asking yourself: I don't build computers, why is this information useful?
The answer is that it is very useful for all sorts of computer programming tasks.

As a simple example, every entry in a disk's file table has a set of attributes 
(Hidden,System,Archived etc).
These attributes as stored as a single number and each bit in that number represents the 
T/F state of one attribute.
 2 = Hidden,4 = System,8 = Volume Label,  16 = Directory all the way up to 131072 (bit 17 
set)
 
 It is easy to test for these attributes.  If an entities attributes value is 22 (16 + 4 + 2) we 
know that the entry is for a hidden,system,directory.
We can isolate and test for any individual value using AND:
IF (value AND 4) = 4 then the "4 bit" must be set so it is a hidden entry. If it is not hidden 
then (Value AND 4) will be 0.
We can change attributes using Or and XOR:
We can ensure that an entry is hidden by ORing it with four to force the 4 bit to be set:value 
= (value or 4)
We can "toggle the entry (if it's hidden, unhide it, if it's not hidden then hide it) by XORing 
it:value = (value XOR 4)


We can do the with any value where individual bits are used as "flags". (changing WIndows 
styles etc.

For those of you familiar with the MODULO operator, if taking a modulo of a power of 2
X = (X AND 255)  is much more efficient than  X = X MOD 256  (or IF x = 256 THEN X = 0 :) 
)


More information about the AccessD mailing list