Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

result of (X and Y)

Posted on 2002-07-17
6
Medium Priority
?
168 Views
Last Modified: 2010-05-02
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
Comment
Question by:damienm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 7159243
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7159251
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
 
LVL 2

Author Comment

by:damienm
ID: 7159254
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 7159290
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
 
LVL 2

Author Comment

by:damienm
ID: 7159304
That explains the result although it does not explain why anyone would want to do this.

Thanks

Damien
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7159308
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question