Bitwise Comparisons

MattS

Crabby Cancerian.....
Local time
Today, 06:09
Joined
Jun 18, 2003
Messages
130
I was hoping somebody could explain how bitwise comparisons work?

The following subroutine (written by somebody else!) sets up a shortcut menu. I'm ok with all of this, except the comparison - i.e. (showoption And 1)

I do not understand how this could return the true/false value needed to set the visible property.

Any help appreciated.

Matt.

NB: Showoption = 0, 5, or 7

Code:
Public Sub SetupMenuOutput(PagenamE As String, Button As Label, Showoption As Integer)
'Sets up rightmouse menu options. Requires maintab pagename, Button to depress and menu options to enable
'3 menuoptions available set by binary 'And'ing. Insert onaction strings into menu
    Set mbar = CommandBars("output")
    With mbar
    .Controls(1).Visible = (Showoption And 1) 'Print
    .Controls(2).Visible = (Showoption And 2) 'XL
    .Controls(3).Visible = (Showoption And 4) 'View
    If Showoption = 0 Then Exit Sub
    .Controls(1).OnAction = "=outputprint('" & ThisPrint & "')"
    .Controls(2).OnAction = "=OutputXL('" & ThisXL & "')"
    .Controls(3).OnAction = "=showpages ('" & PagenamE & "', forms!master!" & Button.Name & ")"
    End With
End Sub
 
Last edited:
Matt,

In boolean:
False = 0
True = "<> 0"

Binary 001 = 1
Binary 010 = 2
Binary 100 = 4

0 And 0 = 0; False
1 And 1 = 1; True

So if the option chosen was 2:

010 And
010
===
010

From Right to left:

0 And 0 = 0
1 And 1 = 1
0 And 0 = 0

By the book, True = -1; False = 0
But your method works.

So "2" And "2" = True ' Not by the book
So "2" And "1" = False ' but it works

The .Visible is set if they chose option 1, 2 or 4.


Wayne
 
Thanks Wayne.
 

Users who are viewing this thread

Back
Top Bottom