Results 1 to 5 of 5

Thread: Bit OR ???

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732

    Bit OR ???

    Hi all,

    I am using the common dialog control to display the print dialog box...

    When this returns I need to check what teh user selected.. eg Collate, PrintToFile, PrintSelection..

    I know these are set in the Common dialogs Flag property, but they are all stored in a single number...

    In VB how can UI check which bits are set?
    Leather Face is comin...


    MCSD

  2. #2
    Si_the_geek
    Guest
    to set them you use something like:

    flags = a OR b OR c


    to check them you do:

    if (flags AND a) = a then ...

  3. #3
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    You can use this code to convert a byte from decimal to binary:
    VB Code:
    1. Public Function CBin(ByVal b As Byte) As String
    2.     Dim i As Long
    3.    
    4.     For i = 7 To 0 Step -1
    5.         If 2 ^ i <= b Then
    6.             CBin = CBin & "1"
    7.             b = b - 2 ^ i
    8.         Else
    9.             CBin = CBin & "0"
    10.         End If
    11.     Next i
    12. End Function
    Just change the "7" to "30" for longs and "14" for integers (as well as the datatype of "b").

    After you use that code on a regular decimal number, you will see a binary number. Each of the 1's and 0's in this binary number can be a flag. When you do this:
    VB Code:
    1. 1000 OR 0010
    you get 1010, which is combining those flags. To test if your four-digit binary number has this flag set: 0010, do this:
    VB Code:
    1. If (XXXX AND 0010) Then Debug.Print "XXXX has flag 0010 set"

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    Thanks victoria.. Worked a treat!


    Sorry for the late reply went home yesterday before I saw your post...
    Leather Face is comin...


    MCSD

  5. #5
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521

    Talking

    It's Victor-- I'm a guy ;P

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