Solved

Vb8 bitwise operation – how they work?

Posted on 2011-09-05
5
211 Views
Last Modified: 2012-05-12
Hi experts!

I’m going to create advanced message box for my application. Look my code

Form_Load
    ' If MsgBox("Are you sure you start Control Center ?", vbYesNoCancel + vbDefaultButton2 + vbQuestion) <> vbYes Then
       If AdvMsgBox("Are you sure you start Control Center ?", vbYesNoCancel + vbDefaultButton2 + vbQuestion) <> vbYes Then
       
End Sub

Private Function AdvMsgBox(sMsg As String, lButton As Long, Optional sTitle As String = "", Optional sContent As String = "") As Long

‘Is there way to check in this style ? This should works, but it always add button, even if I do not send ‘params. Where is the error?

    If (lButton Or vbOK) Then MyButtons = MyButtons Or ButtonOk
    If (lButton Or vbNo) Then MyButtons = MyButtons Or ButtonNo
    If (lButton Or vbAbort) Then MyButtons = MyButtons Or ButtonNo  ‘ in this example here should be not enter, but it does!

End function

Please help. Of course, I have solution with Case where to determine all possible flag of msgBox, I use not more than 10, but I prefer more intelligent solution.
0
Comment
Question by:dvplayltd
  • 3
  • 2
5 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 36486821


This will always test true:
    If (lButton Or vbOK)

I think you mean:
   If (lButton and vbOK)

which tests true only  IButton contains the bit pattern of vbOK

0
 

Author Comment

by:dvplayltd
ID: 36486856
Opps. Yes, my code is with AND, here is with OR becaouse I try for every case with OR insead of AND.


Now I use
If (lButton and vbOK)

and still do not work (it return always True, even if in my case with call vbYesNoCancel + vbDefaultButton2 + vbQuestion in code I compare with )

If (lButton and vbAbort) ' return true
0
 
LVL 42

Expert Comment

by:dqmq
ID: 36489702
I do not understand what this series of statement is trying to accomplish:

    If (lButton Or vbOK) Then MyButtons = MyButtons Or ButtonOk
    If (lButton Or vbNo) Then MyButtons = MyButtons Or ButtonNo
    If (lButton Or vbAbort) Then MyButtons = MyButtons Or ButtonNo

That said, I can tell you that the button mask (lButton) and the msgbox return codes (vbOK, vbNo, vbAbort, etc) are not compatible with one another.  It does not make sense to use both as operands in a bitwise expression.  
0
 

Author Comment

by:dvplayltd
ID: 36491157
Well, my goal is to make replacement of msgbox, but without change params of  500+ message boxes in 10+ programs. For this I need to make recoding of flags as for example I already have code like:

Msgbox  err.description, vbYesNoCancel + vbDefaultButton2 + vbQuestion

I use ActiveX message box which use different codes, for example the up sample is equal to

 TaskDialog.ShowMessage err.description, xptYes + xptNo + xptCancel + xptDefButton2+xptQuestion

I can’t change the values of xptYes , xptNo and so on …

I give up to make it nice. I do it with hard coded numbers (I get integer of all combination I used). It work fine.


0
 

Author Closing Comment

by:dvplayltd
ID: 36491161
10x. I believe you answer with AND is correct, there some other which make mess…
0

Featured Post

Industry Leaders: 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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

733 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