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

x
?
Solved

Vb8 bitwise operation – how they work?

Posted on 2011-09-05
5
Medium Priority
?
227 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
[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
5 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 1500 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 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…
Suggested Courses

715 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