Reasons to use (Boolean) or (Integer) in VBA code?

  • Thread starter Thread starter Clif McIrvin
  • Start date Start date
C

Clif McIrvin

Arrghh!

I simply have not discovered a reliable technique for finding answers
to "why do this instead of that?" questions in the MS helps, so I turn
to you good hearted folk!

I've noticed that True / False parameters are often Integers. It seems
intuitive to me that for testing flags in code Boolean would be
better.

As I'm still fairly early in my application development process I'd
like to find out what the implications of one over the other are.

(Maybe my concern is nothing more than a throwback to the days I was
programming on PDP-8 and NOVA III platforms and we counted both bits
and cycles! -- I've been away from programming for several years, and
the tools have certainly changed!)
 
A value of 0 is False. The Boolean variable's True equates to -1, but any
non-zero value evaluates True.

Not sure it makes an appreciable difference.
 
Thanks Doug -- it's nice to hear a voice with experience confirm my
suspicions.
 
I've noticed that True / False parameters are often Integers. It seems
intuitive to me that for testing flags in code Boolean would be
better.

Does the Boolean type support Null? Do you need to do that?
 
The use of Boolean goes way back to the beginnings of Access, where Integer
was used instead of Boolean. Using a boolean might be more "logical" (no pun
intended), but occasionally it's useful to be able to set Cancel to values
other than -1 (e.g. to use the bit-values to track the reasons why a
procedure was cancelled.)

Some of the more odd-ball developers regularly use Integer instead of Yes/No
fields too. It lets you handle nulls (the JET yes/no data type doesn't), but
more importantly it avoids some crashes and bugs in JET. It's not really
related to your question, but if you want to follow it up:
http://allenbrowne.com/NoYesNo.html
 
Homer J Simpson said:
Does the Boolean type support Null? Do you need to do that?

Assuming Clif was talking about variables, only Variants support Null.
 
Assuming Clif was talking about variables, only Variants support
Null.

That is, an integer wouldn't give you Null values, either.

One of the main reasons I have code that uses integers for Boolean
values is that the Boolean data type in VBA was added after Access
2, where we had to use integers.

The data type should always be the strictest that fits the data
being stored. When you lack a Boolean data type, you have to use an
integer. Conversely, when you want to store more than a Boolean
2-state value, you need some other kind of variable.
 
Warning

David Fenton makes inaccurate and incorrect statements.

I would reccomend finding a certified SQL Server DBA or Developer in
order to fit your database needs.

This 'D A V I D F E N T O N' kid learned his databases on the back of
a cracker jacks box

-Aaron Kempf
MCITP: DBA
 
Doug, David, Allen:

Thank you for an informative discussion. The historical perspective is
both interesting and useful.

You raised issues I hadn't considered, and I can appreciate that while
it seemed a simple question, the answer isn't! <g>

Thank you all again for the education!

--Clif
 
Aaron --

It's been my observation that every son of Adam is cursed with the
necessity of making inaccurate and incorrect statements -- our access
to knowledge and understanding is limited.

FYI, I (and, I would hope, other seekers after assistance) disregard
comments which are so obviously self focused.
 
Back
Top