Home All Groups Group Topic Archive Search About

Or in MsgBox Function

Author
29 Sep 2006 1:51 AM
James
Can someone explain to me what the Or does here?

Dim intReply as Integer =  _
    MsgBox(strPrompt, MsgBoxStyle.OKCancel Or
    MsgBoxStyle.Critical Or MsgBoxStyle.DefaultButton2,
    strTitle)

I don't have VB on this cpu... will it display the ok and cancel
buttons and the critical icon ... i still don't understand
DefaultButton, can someone explain that to me as well? Thanks!

Author
29 Sep 2006 1:58 AM
Adam Ruth
James wrote:
> Can someone explain to me what the Or does here?
>
> Dim intReply as Integer =  _
>     MsgBox(strPrompt, MsgBoxStyle.OKCancel Or
>      MsgBoxStyle.Critical Or MsgBoxStyle.DefaultButton2,
>     strTitle)
>
> I don't have VB on this cpu... will it display the ok and cancel
> buttons and the critical icon ... i still don't understand
> DefaultButton, can someone explain that to me as well? Thanks!
>

In this context, Or is the bitwise operator.  It allows you to combine
bitfield values.  In the way it's being used, it's exactly the same as
using +  For example

If OKCancel = 1 and Critical = 2 and DefaultButton2 = 4 then

OKCancel Or Critical Or DefaultButton2 = 7
OKCancel + Critical + DefaultButton2 = 7

However Or is the better way to do it, since it keeps you from adding
the same value twice:

OKCancel + Critical + DefaultButton2 + OKCancel = 8
OKCancel Or Critical Or DefaultButton2 Or OKCancel = 7

Do an Internet search for "Bitwise Operators" and you'll probably find
some better explanations.

DefaultButton determines which button on the Message Box has focus when
it is shown.  If you pick DefaultButton2 and OKCancel then Cancel would
be in focus an would be the action if the user pressed the space bar or
the Enter key.  DefaultButton1 would be the OK button (left to right).

Adam Ruth
Author
29 Sep 2006 2:16 AM
James
so since sgBoxStyle.OKCancel = 1
MsgBoxStyle.Critical = 16
MsgBoxStyle.DefaultButton2 = 256

does that make the bitwise value 273? which is then the value of
intReply? Sorry, I've never delt with this "bitwise" stuff... What is
this used for? Thanks!


Adam Ruth wrote:
Show quoteHide quote
> James wrote:
> > Can someone explain to me what the Or does here?
> >
> > Dim intReply as Integer =  _
> >     MsgBox(strPrompt, MsgBoxStyle.OKCancel Or
> >      MsgBoxStyle.Critical Or MsgBoxStyle.DefaultButton2,
> >     strTitle)
> >
> > I don't have VB on this cpu... will it display the ok and cancel
> > buttons and the critical icon ... i still don't understand
> > DefaultButton, can someone explain that to me as well? Thanks!
> >
>
> In this context, Or is the bitwise operator.  It allows you to combine
> bitfield values.  In the way it's being used, it's exactly the same as
> using +  For example
>
> If OKCancel = 1 and Critical = 2 and DefaultButton2 = 4 then
>
> OKCancel Or Critical Or DefaultButton2 = 7
> OKCancel + Critical + DefaultButton2 = 7
>
> However Or is the better way to do it, since it keeps you from adding
> the same value twice:
>
> OKCancel + Critical + DefaultButton2 + OKCancel = 8
> OKCancel Or Critical Or DefaultButton2 Or OKCancel = 7
>
> Do an Internet search for "Bitwise Operators" and you'll probably find
> some better explanations.
>
> DefaultButton determines which button on the Message Box has focus when
> it is shown.  If you pick DefaultButton2 and OKCancel then Cancel would
> be in focus an would be the action if the user pressed the space bar or
> the Enter key.  DefaultButton1 would be the OK button (left to right).
>
> Adam Ruth
Author
29 Sep 2006 2:39 AM
Adam Ruth
James wrote:
> so since sgBoxStyle.OKCancel = 1
> MsgBoxStyle.Critical = 16
>  MsgBoxStyle.DefaultButton2 = 256
>
> does that make the bitwise value 273? which is then the value of
> intReply?

Correct, the total of those values is 273.  intReply in your example
would actually be set to a value of type MsgBoxResult which would
indicate which button the user pressed.  273 is a number that is passed
to the function which tells the function how to display the message box.

> Sorry, I've never delt with this "bitwise" stuff... What is
> this used for? Thanks!

No problem, it can be a bit confusing when first encountered.  Bitfields
are a way to combine several options into one parameter.  Instead of
having separate parameters for each of the options, you combine the set
of options into one number with the Or operator.  You'll notice that the
values for each of the options are each double the other one, you have
1, 2, 4, 8, 16, 32, 64, 256, etc.  This is because each number
represents a bit in a 32-bit number.

Wikipedia has a good description of how bitwise operations work.  Think
of the options parameter as a set of 32 on/off switches and each of the
options (that are joined with Or) as turning on one of the 32 options.

http://en.wikipedia.org/wiki/Bitwise

Adam Ruth
Author
29 Sep 2006 11:38 PM
Dennis
You might check out the Flags attribute for Enumerations.  The Flag attribute
makes the or'ing of different enumerations possible such that the receiving
code, i.e.,, msgbox code, can easily decipher what different values of the
Enumeration are passed.

--
Dennis in Houston


Show quoteHide quote
"James" wrote:

> so since sgBoxStyle.OKCancel = 1
> MsgBoxStyle.Critical = 16
>  MsgBoxStyle.DefaultButton2 = 256
>
> does that make the bitwise value 273? which is then the value of
> intReply? Sorry, I've never delt with this "bitwise" stuff... What is
> this used for? Thanks!
>
>
> Adam Ruth wrote:
> > James wrote:
> > > Can someone explain to me what the Or does here?
> > >
> > > Dim intReply as Integer =  _
> > >     MsgBox(strPrompt, MsgBoxStyle.OKCancel Or
> > >      MsgBoxStyle.Critical Or MsgBoxStyle.DefaultButton2,
> > >     strTitle)
> > >
> > > I don't have VB on this cpu... will it display the ok and cancel
> > > buttons and the critical icon ... i still don't understand
> > > DefaultButton, can someone explain that to me as well? Thanks!
> > >
> >
> > In this context, Or is the bitwise operator.  It allows you to combine
> > bitfield values.  In the way it's being used, it's exactly the same as
> > using +  For example
> >
> > If OKCancel = 1 and Critical = 2 and DefaultButton2 = 4 then
> >
> > OKCancel Or Critical Or DefaultButton2 = 7
> > OKCancel + Critical + DefaultButton2 = 7
> >
> > However Or is the better way to do it, since it keeps you from adding
> > the same value twice:
> >
> > OKCancel + Critical + DefaultButton2 + OKCancel = 8
> > OKCancel Or Critical Or DefaultButton2 Or OKCancel = 7
> >
> > Do an Internet search for "Bitwise Operators" and you'll probably find
> > some better explanations.
> >
> > DefaultButton determines which button on the Message Box has focus when
> > it is shown.  If you pick DefaultButton2 and OKCancel then Cancel would
> > be in focus an would be the action if the user pressed the space bar or
> > the Enter key.  DefaultButton1 would be the OK button (left to right).
> >
> > Adam Ruth
>
>
Author
2 Oct 2006 5:01 PM
Steve Long
Hi Dennis,
Just last week I looked this stuff up "again" and it appears that the Flags
attribute doesn't really affect the way the bitmask works, just how the
..ToString() function treats the value.

Correct me if I'm wrong...
Steve

Show quoteHide quote
"Dennis" <Den***@discussions.microsoft.com> wrote in message
news:E8AD6D15-9CAF-4F08-A37F-DA4CD449DBD3@microsoft.com...
> You might check out the Flags attribute for Enumerations.  The Flag
> attribute
> makes the or'ing of different enumerations possible such that the
> receiving
> code, i.e.,, msgbox code, can easily decipher what different values of the
> Enumeration are passed.
>
> --
> Dennis in Houston
>
>
> "James" wrote:
>
>> so since sgBoxStyle.OKCancel = 1
>> MsgBoxStyle.Critical = 16
>>  MsgBoxStyle.DefaultButton2 = 256
>>
>> does that make the bitwise value 273? which is then the value of
>> intReply? Sorry, I've never delt with this "bitwise" stuff... What is
>> this used for? Thanks!
>>
>>
>> Adam Ruth wrote:
>> > James wrote:
>> > > Can someone explain to me what the Or does here?
>> > >
>> > > Dim intReply as Integer =  _
>> > > MsgBox(strPrompt, MsgBoxStyle.OKCancel Or
>> > >  MsgBoxStyle.Critical Or MsgBoxStyle.DefaultButton2,
>> > > strTitle)
>> > >
>> > > I don't have VB on this cpu... will it display the ok and cancel
>> > > buttons and the critical icon ... i still don't understand
>> > > DefaultButton, can someone explain that to me as well? Thanks!
>> > >
>> >
>> > In this context, Or is the bitwise operator.  It allows you to combine
>> > bitfield values.  In the way it's being used, it's exactly the same as
>> > using +  For example
>> >
>> > If OKCancel = 1 and Critical = 2 and DefaultButton2 = 4 then
>> >
>> > OKCancel Or Critical Or DefaultButton2 = 7
>> > OKCancel + Critical + DefaultButton2 = 7
>> >
>> > However Or is the better way to do it, since it keeps you from adding
>> > the same value twice:
>> >
>> > OKCancel + Critical + DefaultButton2 + OKCancel = 8
>> > OKCancel Or Critical Or DefaultButton2 Or OKCancel = 7
>> >
>> > Do an Internet search for "Bitwise Operators" and you'll probably find
>> > some better explanations.
>> >
>> > DefaultButton determines which button on the Message Box has focus when
>> > it is shown.  If you pick DefaultButton2 and OKCancel then Cancel would
>> > be in focus an would be the action if the user pressed the space bar or
>> > the Enter key.  DefaultButton1 would be the OK button (left to right).
>> >
>> > Adam Ruth
>>
>>
Author
2 Oct 2006 11:06 PM
Dennis
All I know is what I read in the MSDN under Flags attributes.
--
Dennis in Houston


Show quoteHide quote
"Steve Long" wrote:

> Hi Dennis,
> Just last week I looked this stuff up "again" and it appears that the Flags
> attribute doesn't really affect the way the bitmask works, just how the
> ..ToString() function treats the value.
>
> Correct me if I'm wrong...
> Steve
>
> "Dennis" <Den***@discussions.microsoft.com> wrote in message
> news:E8AD6D15-9CAF-4F08-A37F-DA4CD449DBD3@microsoft.com...
> > You might check out the Flags attribute for Enumerations.  The Flag
> > attribute
> > makes the or'ing of different enumerations possible such that the
> > receiving
> > code, i.e.,, msgbox code, can easily decipher what different values of the
> > Enumeration are passed.
> >
> > --
> > Dennis in Houston
> >
> >
> > "James" wrote:
> >
> >> so since sgBoxStyle.OKCancel = 1
> >> MsgBoxStyle.Critical = 16
> >>  MsgBoxStyle.DefaultButton2 = 256
> >>
> >> does that make the bitwise value 273? which is then the value of
> >> intReply? Sorry, I've never delt with this "bitwise" stuff... What is
> >> this used for? Thanks!
> >>
> >>
> >> Adam Ruth wrote:
> >> > James wrote:
> >> > > Can someone explain to me what the Or does here?
> >> > >
> >> > > Dim intReply as Integer =  _
> >> > > MsgBox(strPrompt, MsgBoxStyle.OKCancel Or
> >> > >  MsgBoxStyle.Critical Or MsgBoxStyle.DefaultButton2,
> >> > > strTitle)
> >> > >
> >> > > I don't have VB on this cpu... will it display the ok and cancel
> >> > > buttons and the critical icon ... i still don't understand
> >> > > DefaultButton, can someone explain that to me as well? Thanks!
> >> > >
> >> >
> >> > In this context, Or is the bitwise operator.  It allows you to combine
> >> > bitfield values.  In the way it's being used, it's exactly the same as
> >> > using +  For example
> >> >
> >> > If OKCancel = 1 and Critical = 2 and DefaultButton2 = 4 then
> >> >
> >> > OKCancel Or Critical Or DefaultButton2 = 7
> >> > OKCancel + Critical + DefaultButton2 = 7
> >> >
> >> > However Or is the better way to do it, since it keeps you from adding
> >> > the same value twice:
> >> >
> >> > OKCancel + Critical + DefaultButton2 + OKCancel = 8
> >> > OKCancel Or Critical Or DefaultButton2 Or OKCancel = 7
> >> >
> >> > Do an Internet search for "Bitwise Operators" and you'll probably find
> >> > some better explanations.
> >> >
> >> > DefaultButton determines which button on the Message Box has focus when
> >> > it is shown.  If you pick DefaultButton2 and OKCancel then Cancel would
> >> > be in focus an would be the action if the user pressed the space bar or
> >> > the Enter key.  DefaultButton1 would be the OK button (left to right).
> >> >
> >> > Adam Ruth
> >>
> >>
>
>
>