Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TRUE is not TRUE anymore?

Status
Not open for further replies.

kewo99

Technical User
Oct 7, 2002
90
0
0
US
I went home last Friday with my Access 2003 apps (using ODBC SQL Server backends) working fine (and have functioned for several months). Monday I have issues with all of the True/False fields.
Investigation finds that only -1 is being recognized as True. Previously any non-zero value was recognized as True.

This used to work:
Dim A as Integer
A=1
If A = True Then
<this code would execute before but not now>
End If

This does work:
Dim A As Integer
A=1
If A Then
<this code will still execute now>
End If

Thanks for any enlightenment.

Ken
 
Hi Kewo

Just to reasure you, I had a similar problem when I check for a true condition and as your own posting states...

if variable then
<code>
end if

should work, so I suggest, that's the way ahead. I'm not sure if its to do with null values in the data but I was checking for a msgbox reply and comparing for true would not work with it. vbOK did though.

Ian M


Program Error
Why is it, I still think in terms of spectrum BASIC!
 
In Access (and VB, I believe) True = -1 and False = 0, but you'll often find that when testing, 0 evaluates to False, all other numeric values evaluate to True. If you use a bit field in SQL server, I think True = 1 and False = 0.

The comparision "if a = True then" I think would compare whatever value is contained in "a" with -1, which will evaluate to either True or False depedning on "a" being -1 or some other value (all other values than -1 will evaluate to False).

I think the comparision "if a then" will evaluate to True with any numeric value other than 0.

So I think either you have done some changes (i e picking the integer directly from a bit field for test om stead of first assigning it to a boolean, or added the " = True" part) or there's been a logical bomb in the system that hasn't been detected until now.

Roy-Vidar
 
RoyVidar has explained well..
In my experience
Code:
Dim A As [b]Boolean[/b]
A=1
If A = True Then
       ' This will work
End If
Code:
Dim A As [b]Integar[/b]
A=1
If A = True Then
       ' Never worked
End If


Zameer Abdulla
[sub]Jack of Visual Basic Programming, Master in Dining & Sleeping[/sub]
Visit Me
 
When you dimension a variable as Boolean, assigning any non-zero number to the variable will automatically make the variable's value -1. So if you assign A=1 to a boolean variable A, its value will be -1, not 1.

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top