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. Charles -----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 To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: COBOL Question 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