[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

result of (X and Y)

I am working on a maintenace system which has code which I do not understand,

basically it has:

Public Sub Load(lngOptions As Long)

If (lngOptions And 1) = 0 then
     'Do something
     MsgBox "Got here 1"
End If
If (lngOptions And 2) = 0 then
     'Do something else
     MsgBox "Got here 2"
End If
If (lngOptions And 4) = 0 then
     'Do something
     MsgBox "Got here 4"
End If
If (lngOptions And 32) = 0 then
     'Do something else
     MsgBox "Got here 32"
End If

End Sub

(I have added the message boxes)

So if I have,

Private Sub Command1_Click()
Call Load(1)
End Sub

All but the first msgbox come up but if I have Call Load(10) all but the second 1 will come up.  So basically I am looking for some sort of general Algorithm to determine what the result of (X And Y) where X and Y are Integers.

Thanks

Damien
0
damienm
Asked:
damienm
  • 3
  • 2
1 Solution
 
gencrossCommented:
Do you want to add X and Y together and return the result?  Where are the values of X and Y in the code?

Please give details on exactly what you want to accomplish.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
the X AND Y returns the bitwise result, so you have to "see" the integers in their bit representation:

0 -> 00000000
1 -> 00000001
2 -> 00000010
3 -> 00000011
4 -> 00000100
5 -> 00000101
6 -> 00000110
7 -> 00000111
etc
10-> 00001010

10 AND  1 -> 1010 AND 00001 -> 0
10 AND  2 -> 1010 AND 00010 -> 1
10 AND  4 -> 1010 AND 00100 -> 0
10 AND 32 -> 1010 AND 10000 -> 0

CHeers



0
 
damienmAuthor Commented:
I want to know if I have e.g.

msgbox (1 And 2)

or

msgbox (4 And 2)

What will be returned without me having to run the code.

So a general algorithm

for the result of
(X And Y)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
in fact, my last output was incomplete:

10 AND  1 -> 01010 AND 00001 -> 00000 -> 0
10 AND  2 -> 01010 AND 00010 -> 00010 -> 2
10 AND  4 -> 01010 AND 00100 -> 00000 -> 0
10 AND 32 -> 01010 AND 10000 -> 00000 -> 0

bitwise AND returns a bit set to 1 only if that bit for both input was set to 1, otherwise the result is 0 for that bit.

CHeers
0
 
damienmAuthor Commented:
That explains the result although it does not explain why anyone would want to do this.

Thanks

Damien
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
the explanation is simply that instead of passing x boolean arguments, you pass 1. The advantage is that if you add another IF( ), you don't need to change the procedure arguments, which can be important for versioning (compatibility).
CHeers
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now