Results 1 to 4 of 4

Thread: vb6 true/false vs mysql tinyint(1)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    118

    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?

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: vb6 true/false vs mysql tinyint(1)

    I prefer to check like with like
    Code:
    if CBool(temprst.Fields("Monday")) = True then

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: vb6 true/false vs mysql tinyint(1)

    Quote Originally Posted by dilettante View Post
    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
    Code:
    If fred Then
    *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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width