'Why is Boolean's size in vba 2 Bytes?

In my apprenticeship we started doing now vba at school. When our teacher handed us out the data type summary, I was kind of confused. .....

Boolean -> 2 Bytes -> Range: True / False

Well True / False is of course plausible but, Why are 2 Bytes used, as Booleans hast just to be able, to represent any of 2 values? I mean theoretical we could use a single Bit for representing any value of this range. (But I know thats senseless, as we are using Highlevel-Languages)

As I asked my teacher this, he appeared as he had never asked him self the same, and after a few seconds of cogitation, he just finished this with an answer of the kind "You have to accept it, as it is, what it is." But I wouldn't call my self a good programmer, if I were just 'using', and would never be interested in understanding. So I'm asking now here:

Is there any reason in vba, why Boolean needs 2 Bytes instead of a single Byte?



Solution 1:[1]

For backwards compatibility with the original Microsoft BASIC.

Microsoft BASIC only had 3 types:

  • Integer (16-Bit)
  • Single (32-Bit)
  • String
  • (...and Arrays of the above types)

The Boolean data type didn't exist in Microsoft BASIC and only existed internally (as part of expressions).

10 INPUT "Do you want more stars? "; A$
20 IF LEN(A$) = 0 THEN GOTO 90

I'd speculate therefore that originally Boolean was created internally as an Integer. Later when upgraded to 32-bit, Boolean remained at 16-bit for backward compatibility. And I'd doubt Byte didn't exist until Visual Basic. However that's all speculation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sancarn