True Comparison Expression returns -1, why? (1 Viewer)

BigHappyDaddy

Coding Monkey Wanna-Be
Local time
Today, 14:26
Joined
Aug 22, 2012
Messages
205
I must say, extremely interesting discussion.

Does that mean BigHappyDaddy.IsDrunk = False? :)
 

static

Registered User.
Local time
Today, 22:26
Joined
Nov 2, 2015
Messages
823
I'm not missing your point I just couldn't give a rats ass what a boolean is at the point I can't do anything about it.

"The OP's problem is simply that"

He doesn't know what google is?

"in the absence of formatting instructions, the VBA methods of examining that storage unit look at it as a BYTE rather than a Boolean."

Exactly! Yay! We aggree.

This is an Access forum and the question as I see it is "why is a boolean value formatted the way it is in an Access table."

In an Access table, a boolean is not called a boolean or bit or whatever, it is called Yes/No.

I was simply suggesting that the OP format the return value of his calculated field as any other boolean field would be formatted.

He doesn't need Cbool anything because there are built in properties to handle the formatting.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:26
Joined
Feb 28, 2001
Messages
27,192
Static:

I was simply suggesting that the OP format the return value of his calculated field as any other boolean field would be formatted.

We don't disagree about what needs to be done, only about how, perhaps.

My suggestion was that EXPLICIT formatting (as for example use of CBool) is needed because the default IN HIS SITUATION was not Boolean, but BYTE INTEGER, the underlying datatype for the typecast of Boolean. That is how he saw the -1 when he was expecting TRUE. It was caused by asking the wrong question (using the wrong format, if you prefer).

Is it possible that the OP erred in the command he gave by omitting a formatting option? Probably. Is this a bug in Access that it didn't stop him? Damfino, but maybe not.

We have to remember that VBA is Visual BASIC for Applications, but that the acronym is multi-layered. The language specification for BASIC is a bit loose because BASIC is "Beginner's All-purpose Symbolic Instruction Coding." The original thrust of the language was to be forgiving, unlike ADA or PL/1, because it was targeted towards beginners who were more likely to make errors. So VBA might not have complained, it simply did an (invisible) typecast and showed -1 in a context where that seemed to be the right answer even though it was confusing.

As to whether the OP knows what Google is, there we are again probably on common ground. Except that we should remember that for some newer folks, they don't know enough yet to ask the right question. I remember how TERRIBLY noobie I was for my first few posts on this forum until I learned to do a search and not give up if it happened that my first couple of keywords produced nothing useful. That's why I try to show some patience to the new members who ask a question that might be answerable on Google. But this particular question might have been a bit harder to trace down because the reason is a bit more obscure.
 

static

Registered User.
Local time
Today, 22:26
Joined
Nov 2, 2015
Messages
823
1=1=true is pretty explicit.

It doesn't really matter. I stated my case and you stated yours. ;)
OP probably doesn't care by this point.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 22:26
Joined
Sep 12, 2006
Messages
15,658
irrespective of whether it makes sense or not, and it probably doesn't, VBA treats -1 as TRUE, and 0 as FALSE.

Interestingly

? 0 = False - returns true
? -1=true - returns true

and everything else
? 1= false - returns false
? 1= true - also returns false
 
Last edited:

static

Registered User.
Local time
Today, 22:26
Joined
Nov 2, 2015
Messages
823
Well exactly.

If you ask why does Access or Excel or Powerpoint show -1 as true? the answer is just 'because it does'.

It's nothing to do with the OS or anything, it's just that whoever coded VBA decided that true would be -1. C type languages might be 1. Neither is right or wrong, you just have to know what to expect, although in most cases 0 is false and <>0 is true... so it doesn't really matter.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:26
Joined
Feb 28, 2001
Messages
27,192
Just to heap on the indignity...

In some implementations of BASIC (not VBA), it is odd/even that becomes True/False because they go only by the low-order bit. I can think of at least two cases where this is so.

So there we DO agree, static. "Just because it does it that way."

Reminds me of many losing arguments with Mom and Dad... "Why?" "Because I said so, that's why."
 

Users who are viewing this thread

Top Bottom