vb6 true/false vs mysql tinyint(1)
hi... i have query which i m not sure about...
eg: i have this code in VB6;
Code:
if temprst.Fields("Monday")= true then
some action
else
some action
end if
the code will always jump to the else block no matter what value is store in the field monday... but if i change the = true to =1 then everything works correctly..
temprst is declared as ADODB.Recordset, i am using mySQL server 5.5
the Field Monday ha the data type tinyint(1)
i thought that a 1 in tinyint will be treated as true in vb6?
Re: vb6 true/false vs mysql tinyint(1)
I prefer to check like with like
Code:
if CBool(temprst.Fields("Monday")) = True then
Re: vb6 true/false vs mysql tinyint(1)
Testing for "= True" is goofy at best anyway. The If statement already tests whether the expression is True. That's why it exists!
It is far, far clearer (and generates just as good code) if you simply say what you really mean:
Code:
If temprst.Fields("Monday").Value = 1 Then
or perhaps:
Code:
If temprst.Fields("Monday").Value <> 0 Then
Also:
Relying on default properties can be a bad thing, and it may eventually bite you when it leads to a bug which will be very hard to find.
Re: vb6 true/false vs mysql tinyint(1)
Quote:
Originally Posted by
dilettante
Testing for "= True" is goofy at best anyway. The If statement
already tests whether the expression is True. That's why it exists!
It is far, far clearer (and generates just as good code) if you simply say what you really mean:
Code:
If temprst.Fields("Monday").Value = 1 Then
or perhaps:
Code:
If temprst.Fields("Monday").Value <> 0 Then
Also:
Relying on default properties can be a bad thing, and it may eventually bite you when it leads to a bug which will be very hard to find.
Good point as long as there is some sort of naming convention being used.
Statements like
*really* annoy me - have to go and try to find out what 'fred' is - and then if it's not a Boolean, try to remember what True and False are numerically (for the language in use), and at my age I've got better things to remember :)