Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2001
    Posts
    45

    Unanswered: Syntax problem: Reading out bits out of a byte

    I am saving several bit-flags in a Byte field which I am using in a continous form to fill some checkboxes (Value 1 = Checkbox 1, Value 2 = Checkbox 2, Value 3 = Checkbox 1 + 2, etc.). Now I am trying to find a way to to parse this byte by bit-comparison inside the recordsource property of the checkbox. Just can't find the proper syntax - none of these work:

    (for example Checkbox No.4

    =If([intByte] && 8; True; False)
    =If([intByte] & 8; True; False)
    =If([intByte] And 8; True; False)

    Is it possible that there is no way of comparing by Bit?

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    8 AND 10 = 8

    so you need:
    iif(([intByte] And 8)=8, True, False)



    izy

  3. #3
    Join Date
    Nov 2001
    Posts
    45
    Thanks.... but unfortunately it didn't work. I never get 'True' results, 'False' only...

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    looks like we need to force the data type so that we are comparing bits in similar apples.

    this should work:

    iif((int([intByte]) And int(8))=0, False, True)

    ...note the true/false reversal.


    izy

  5. #5
    Join Date
    Nov 2001
    Posts
    45
    Thank you izy, but still no luck....
    I tried this way now:

    (ControlSource =bitCompare([intGradeCode];3)

    (VBA-Code
    Function bitCompare(intByte, intBitNumber) As Boolean
    If (intByte And 2 ^ intBitNumber) Then bitCompare = True Else bitCompare = False
    End Function

    That seems to work. But now I'm facing another, different problem: Since the checkboxes are not really connected to the recordset, they seem to be write-protected. Which is ok, I would only the Click-Event to re-recalculate the new intGradeCode. But I am not even allowed to CLICK on the checkbox....

    Do you have an idea? Or does it seem I can't get around real boolean values? (that is 12 times the amount of data; 1 Bool = 2 Bytes -> 12 Bytes for six Checkboxes)

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    interesting!

    my iif with type-force worked for me this morning but then i tested with int(textBoxValue) AND int(textBoxValue)
    -also with
    int(HardCodedValue) AND int(textBoxValue)

    ...maybe it would fly if you used integer instead of byte in your table, but you have a good fix now anyway.

    --

    if you have a series of checkboxes that are linked by ControlSource to your bit fields, editing is going to be tough!

    how about a second set of check boxes in the footer/header set in code by the onCurrent event and an UpdateTo button that recalculates your byte.

    izy

  7. #7
    Join Date
    Nov 2001
    Posts
    45
    Interesting approach, but I am using this in a continoues form; so there is no real comfortable way of letting the user know, what recordentry he/she actually edits when working in the header.... oh boy...

  8. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    maybe cheating will suit your app

    display a limited subset of your data in the continuous forms - enough to let the user choose one to play with. disallow edits so your user is not tempted to play there (lock/disable or allowEdits=false or...)

    _onCurrent, display the full record in the header (...or footer ...or a pop-up) together with the hidden "real" check-boxes and the visible "fake" check boxes as discussed earlier.

    there's upside: not only do you get your bit fields to work, but you end up with less crowded contForms (or more recs to a window).

    i end up doing this a lot. not 'cos of bit fields, but 'cos i often have too much stuff to put in contForms.
    e.g. address lists: user is unlikely to want to select a record to edit based on [dogsName], [golfHandicap], [shoeSize]..., for me it's enough to have a few likely fields [name], [company], [lastOrder] on show in the contForms. in effect i'm using contForms as a sort-of list but with the nicer formatting etc that you can get in the forms.

    ...having said all that - mentioning pop-up gives me another idea!

    see if you can get some sort of event triggered on your locked check boxes in the contFroms (i didn't try, but maybe _click or _gotFocus works). if yes: pop-up a window with enough fields to keep the user happy that he is editing the right record plus the "fake" checkboxes plus Update / Cancel buttons.


    izy

  9. #9
    Join Date
    Nov 2001
    Posts
    45
    Yes!!!! Thanks izy, you got me onto the right path. since ONCLICK didnt work, ONFOCUS does the trick! Now I have a working event and can set/unset any values in any way I want it (I am using functions now to manipulate the original Byte-value; as soon as I change this one, the checkbox-controlsource is updated by its own)! Thanks a lot man!

    Only flaw: When the clicks on the checkbox, there is still the windows-error-beep-sound... but thats a different story

  10. #10
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    Originally posted by izyrider
    8 AND 10 = 8

    so you need:
    iif(([intByte] And 8)=8, True, False)



    izy
    not with sql and is a boolean operator ie returns true or false

    SELECT 8 And 10 AS e, True AS e2;

    proves the point

    if you still want to use sql try just [intByte] and ensure it's correctly reading the variable
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

Posting Permissions

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