Solved

Vb8 bitwise operation – how they work?

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

707 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

17 Experts available now in Live!

Get 1:1 Help Now