I believe the explanation has to do with how older programming languages (WordBasic and early VBA) stored the integer values of True and False. In those days, True = -1 and False = 0.
Newer programming languages still use 0 for False, but 1 for True.
The majority of Word's Boolean type properti...
Sub test()
Dim a As Boolean
a = 2
Dim b As Boolean
b = CBool(2)
Dim c As Boolean
Dim d As Boolean
c = Not a
d = Not d
Debug.Print CInt(a), a, Not a, c
Debug.Print CInt(b), b, Not b, d
End Sub
Private Type t1
b As Boolean
End Type
Private Type t2
i As Integer
End Type
Public Sub testbits()
Dim b As t1
Dim i As t2
Dim i2 As t2
i.i = 256
LSet b = i
LSet i2 = b
Debug.Print i.i, b.b, i2.i
End Sub
256 True 256
This seems a good case as to why you should not If Not <condition> Then but rather If <condition> = False Then
using OP's code, I had CInt(X) return 2. With X declared As Boolean, my (previous?) understanding of VBA was that this would be impossible and CInt(X) could only ever be 0 or -1
Anyway: That's why I usually advocate for writing conditions in either If <condition> Then or If <condition> = False Then; anything else is just a time bomb
it also bears pointing out that Not, And, and Or are bitwise operators, not logical operators, even though we pretend it could be used like logical ones.
and because we don't have an Option Strict, it's too easy to accidentally end up with a implicit Variant result from a <condition>; so for that reason, I can't even trust If someFunctionThatReturnsABoolean() = True Then
In short, you want to ensure that all your condition can only yield a falsy result because falsy result is the only one that's constant everywhere.... Everyone (well, except JS...) expect a falsy result to be one that's equal to 0.
But not everyone agrees on what constitutes a truthy result -- some say 1, others say -1, yet other say true, etc. etc. Confusion abounds.
@MathieuGuindon Winter Christmas is coming. You can gift everyone you ever told to just do If foo Then an apology. Check that list not -3 times though.
the issue, though is that you can't guarantee that you won't get hit with an implicit conversion when evaluating an expression. The above works in all cases, explicit booleans or not.
and I prefer a coding style that is always correct even in face of absurdity.
given that VBA has no distinct logical operators, you'd be looking at writing If Not CBool(<condition>) Then to get the same behavior as C/C++'s if(!<condition>)
If <condition> = False Then has the same meaning & behavior but does with less words.
A small revision:
Public Sub testbits()
Dim b As t1
Dim i As t2
Dim i2 As t2
i.i = 256
LSet b = i
LSet i2 = b
Debug.Print i.i, b.b, CInt(b.b), i2.i
End Sub
that does proves that the Boolean can store a value other than True/False, providing that you don't use VBA's usual way of assigning values.
at one point I thought as long it's converted into boolean, but I ran into another case where that is a dangerous assumption due to VBA's implicit here-let-me-manhandle-this-for-you-because-we-know-you-are-a-dumb-schmuck-and-I-know-better conversion.
That particular one, yes, should be apologized for. :)
To add on to Cindy's excellent answer, I want to point out that while VBA normally has safeguards to coerce the values when assigning to a Boolean data type, this can be circumvented. Basically, if you write a random value to a memory address that's not yours, then you should expected undefined b...
So, if I understand this correctly, the problem is that somebody at MS goofed up and forgot to send the return value generated in C++ through oleaut or similar before returning it as Boolean in VBA.
> Version 2.4.1.20935 OS: Microsoft Windows NT 10.0.18362.0, x64 Host Product: Microsoft Office 2013 x86 Host Version: 15.0.5023.1000 Host Executable: EXCEL.EXE
**Description** This is an intermittent issue. When using the hotkey `Ctrl+T` to open a new browser tab, which is also the same as Find Symbol, RD is latching onto it. RD displays the Find Symbol dialog even though the VBA IDE isn't the active window.
**To Reproduce** Steps to reproduce the behavior: 1. Have VBA IDE open in
we're waiting for some CS translations. other than that, ..I'd like the inspection results toolwindow scrollbars to behave and not wreck the bottom panel layout, but that's rather minor
first time after opening a workbook a boolean function fails to pass "true". not sure what to do to fix that; after that first use, everything runs smooth
git: Hey. All these changes happened.
Iven: That's cause they casing changed. I'm not concerned.
git: Hey. All these changes happened.
Iven: I know *casing* changed.
git: Hey. All these changes happened.
Iven: FML...
ok, one of these days i'll get back to reading mat's blog about class modules; i feel like that would have helped me on this, but i'm a glutton for punishment...
off to clean the house before i have to get kids. night folks!
and implement both interfaces in its code module but yes, you can certainly add a Control As IFormControl to a "more derived" interfaces like IFormButtonControl
Here we go again, the Winter Bash is here and the hats are listed below.
The list has the same format as always, there are only two answers: one for the secret hats, and one for the regular hats. The secret hat list will be updated as we learn them.
Only edit the secret hat answer with definiti...
#TIL Left click to hold and drag a window. While dragging, wiggle the window back and forth. It'll minimize all the other windows but the one you're dragging. Release the mouse button and now that's the only window not minimized. If you don't want to actually minimize before letting go of the left click button press Esc to cancel the minimize.