Solved

Vb8 bitwise operation – how they work?

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Specify ip address in my connection string for sas 2 59
VBA open file from excel cell 4 42
change vba from autofit to 13.5 width? 4 29
Excel - Save a copy of work book 13 84
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…
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…
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 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…

776 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