Really, a different operator?  I didn't know; I bought a C compiler once, a 
couple decades ago, but then never used it.

Now I'm wondering whether VBA has such a distinction and I simply assumed, and 
never looked for it.  I don't think so, but I should remember to look.

---
Bob Bridges, robhbrid...@gmail.com, cell 336 382-7313

/* Good teaching is one-fourth preparation and three-fourths good theatre.  
-Gail Godwin */

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf 
Of Charles Mills
Sent: Saturday, June 6, 2020 11:35

The problem would seem to me to stem from having the same operator for Boolean 
Not and for Bit Complement. Apparently VBA uses ! for both.

I believe that in C or C++ if ( ! Result ) would evaluate as you expected: 
first Result would be evaluated as true or false, then that truth value would 
be logically inverted, and then that inversion evaluated as true or false. C 
has a separate operator for complement -- the tilde ~ -- and in C you would 
have to code if ( ~ Result ) to get the anomalous behavior you describe.

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf 
Of Bob Bridges
Sent: Friday, June 5, 2020 11:00 PM

Reminds me of a situation I had some years ago while writing a VBA program that 
used a class (for FTP, I think) that had been written in some flavor of C.  I 
was testing a supposedly Boolean return code and getting unexpected results.  I 
tried several ways, and eventually proved to myself that the return code was 
both True and False.  That is:

  Result = Function(Argument)
  If Result Then MsgBox "True"
  If Not Result Then MsgBox "False"

...displayed ~both~ messages.  Maybe some of you already know what was 
happening here, but I had to examine the returned value in hex to catch on.  
VBA uses -1 (1111 1111b) for True and 0 (0000 0000b) for False, but evaluates 0 
as False and any non-zero number as True.  The Not operand uses two's 
complement to negate.  But C, I gather, uses 0 for False and 1 for True.  So in 
this case I was getting a 1 back from the function (0000 0001b), which VBA 
evaluated as True - and when I said "Not Result", it negated 1 into -2 (1111 
1110b) and evaluated that as True also.

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to