Solved

Vb8 bitwise operation – how they work?

Posted on 2011-09-05
5
199 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

943 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now