By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

Msgbox parameter Or operator questions

P: n/a
Hello

I'm sure that anyone with VB.NET would be familiar with the msgbox parameter syntax

Dim msg As Strin
Dim title As Strin
Dim style As MsgBoxStyl
Dim response As MsgBoxResul
msg = "Do you want to continue?" ' Define message
style = MsgBoxStyle.DefaultButton2 Or
MsgBoxStyle.Critical Or MsgBoxStyle.YesN
title = "MsgBox Demonstration" ' Define title
' Display message
response = MsgBox(msg, style, title

So I pass in something like

style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or MsgBoxStyle.YesN

And it knows that I want a message box with a Yes and a No button, an exclamation point icon, and make the No button the default

DefaultButton2 = 256, critical = 16, and YesNo =

When I do the style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or MsgBoxStyle.YesNo, I see style = 276

The "+" operator will work as well, but the Intellisense doesn't work when I do this

I can't find this functionality of the "Or" operator documented anywhere

What I'm trying to do is something like

Begin Pseudo code ===============

Private Enum MyEnu
MyVal0=
MyVal1=
MyVal2=
End Enu

Dim MyVar as MyEnu

If MyCriteria1= True The
MyVar = MyVal
End I

If MyCriteria2 True The
MyVar = MyVar Or MyVal
End I

If MyVar Was assigned to MyVal0 The
'Do Somethin

If MyVar Was Assigned to MyVal1 The
'Do Somethin

End Pseudo code ===============

I can change MyEnum such that MyVal0 = 4, MyVal1 = 16, etc. and then do a
If MyVar Mod MyVal1 = 0 the
MyVar -= MyVal

If MyVar Mod MyVal0 = 0 the
'Do somethin

'Go to the next smallest MyVa

Any idea how the messagebox function does it

Thanks
Eric
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi, it's all with bits...

Your flags should start from 1, then double themselves...

<Flags()> _
Public Enum MyEnum
Val1 = 1
Val2 = 2
Val3 = 4
Val4 = 8
End Enum

Then, you can "Or" them into your variable:

'==
Dim MyVar As MyEnum = MyEnum.Val1 Or MyEnum.Val3
'==

And to test for their presence, you need to "And" them...

'==
If (MyVar And MyEnum.Val1) = MyEnum.Val1 Then
' Val1 is in there
End If

If (MyVar And MyEnum.Val2) = MyEnum.Val2 Then
' Val2 is in there
End If

If (MyVar And MyEnum.Val3) = MyEnum.Val3 Then
' Val3 is in there
End If

If (MyVar And MyEnum.Val4) = MyEnum.Val4 Then
' Val4 is in there
End If
'==

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
"Eric Goforth" <an*******@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
Hello,

I'm sure that anyone with VB.NET would be familiar with the msgbox parameter syntax:
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
msg = "Do you want to continue?" ' Define message.
style = MsgBoxStyle.DefaultButton2 Or _
MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
title = "MsgBox Demonstration" ' Define title.
' Display message.
response = MsgBox(msg, style, title)

So I pass in something like

style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
And it knows that I want a message box with a Yes and a No button, an exclamation point icon, and make the No button the default.
DefaultButton2 = 256, critical = 16, and YesNo = 4

When I do the style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or MsgBoxStyle.YesNo, I see style = 276.
The "+" operator will work as well, but the Intellisense doesn't work when I do this.
I can't find this functionality of the "Or" operator documented anywhere.

What I'm trying to do is something like:

Begin Pseudo code ================

Private Enum MyEnum
MyVal0=0
MyVal1=1
MyVal2=2
End Enum

Dim MyVar as MyEnum

If MyCriteria1= True Then
MyVar = MyVal0
End If

If MyCriteria2 True Then
MyVar = MyVar Or MyVal1
End If

If MyVar Was assigned to MyVal0 Then
'Do Something

If MyVar Was Assigned to MyVal1 Then
'Do Something

End Pseudo code ================

I can change MyEnum such that MyVal0 = 4, MyVal1 = 16, etc. and then do a
If MyVar Mod MyVal1 = 0 then
MyVar -= MyVal1

If MyVar Mod MyVal0 = 0 then
'Do something

'Go to the next smallest MyVal

Any idea how the messagebox function does it?

Thanks,
Eric

Nov 20 '05 #2

P: n/a
* =?Utf-8?B?RXJpYyBHb2ZvcnRo?= <an*******@discussions.microsoft.com> scripsit:
I'm sure that anyone with VB.NET would be familiar with the msgbox parameter syntax:

Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
msg = "Do you want to continue?" ' Define message.
style = MsgBoxStyle.DefaultButton2 Or _
MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
title = "MsgBox Demonstration" ' Define title.
' Display message.
response = MsgBox(msg, style, title)

So I pass in something like

style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or MsgBoxStyle.YesNo

And it knows that I want a message box with a Yes and a No button, an exclamation point icon, and make the No button the default.

DefaultButton2 = 256, critical = 16, and YesNo = 4

When I do the style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or MsgBoxStyle.YesNo, I see style = 276.

The "+" operator will work as well, but the Intellisense doesn't work when I do this.

I can't find this functionality of the "Or" operator documented anywhere.

What I'm trying to do is something like:

Begin Pseudo code ================

Private Enum MyEnum
MyVal0=0
MyVal1=1
MyVal2=2
End Enum

Dim MyVar as MyEnum

If MyCriteria1= True Then
MyVar = MyVal0
End If

If MyCriteria2 True Then
MyVar = MyVar Or MyVal1
End If

If MyVar Was assigned to MyVal0 Then
'Do Something

If MyVar Was Assigned to MyVal1 Then
'Do Something

End Pseudo code ================


\\\
<Flags()> _
Public Enum MyMessageBoxStyles
CancelButton = 1
Exclamation = 2
HelpButton = 4
SystemModal = 8
End Enum

Public Function MyMessageBox(ByVal Styles As MyMessageBoxStyles) As String
If (Styles And MyMessageBoxStyles.CancelButton) <> 0 Then
AddCancelButton(...)
End If
If (Styles And MyMessageBoxStyles.Exclamation) <> 0 Then
AddExclamationMark(...)
End If
Nov 20 '05 #3

P: n/a
Eric,
In addition to the others comments, I find the shift operator in VB.NET 2003
useful to define a Flags enum:

<Flags()> _
Public Enum MyEnum
Val1 = 1 << 0
Val2 = 1 << 1
Val3 = 1 << 2
Val4 = 1 << 3
End Enum

As it "tells" me Val1 is the 0 bit, Val2 is the 1 bit, Val3 is the 2 bit,
Val4 is the 3 bit...

Hope this helps
Jay

"Eric Goforth" <an*******@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
Hello,

I'm sure that anyone with VB.NET would be familiar with the msgbox parameter syntax:
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
msg = "Do you want to continue?" ' Define message.
style = MsgBoxStyle.DefaultButton2 Or _
MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
title = "MsgBox Demonstration" ' Define title.
' Display message.
response = MsgBox(msg, style, title)

So I pass in something like

style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
And it knows that I want a message box with a Yes and a No button, an exclamation point icon, and make the No button the default.
DefaultButton2 = 256, critical = 16, and YesNo = 4

When I do the style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or MsgBoxStyle.YesNo, I see style = 276.
The "+" operator will work as well, but the Intellisense doesn't work when I do this.
I can't find this functionality of the "Or" operator documented anywhere.

What I'm trying to do is something like:

Begin Pseudo code ================

Private Enum MyEnum
MyVal0=0
MyVal1=1
MyVal2=2
End Enum

Dim MyVar as MyEnum

If MyCriteria1= True Then
MyVar = MyVal0
End If

If MyCriteria2 True Then
MyVar = MyVar Or MyVal1
End If

If MyVar Was assigned to MyVal0 Then
'Do Something

If MyVar Was Assigned to MyVal1 Then
'Do Something

End Pseudo code ================

I can change MyEnum such that MyVal0 = 4, MyVal1 = 16, etc. and then do a
If MyVar Mod MyVal1 = 0 then
MyVar -= MyVal1

If MyVar Mod MyVal0 = 0 then
'Do something

'Go to the next smallest MyVal

Any idea how the messagebox function does it?

Thanks,
Eric

Nov 20 '05 #4

P: n/a
Nice! :-)

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eI*************@tk2msftngp13.phx.gbl...
Eric,
In addition to the others comments, I find the shift operator in VB.NET 2003 useful to define a Flags enum:

<Flags()> _
Public Enum MyEnum
Val1 = 1 << 0
Val2 = 1 << 1
Val3 = 1 << 2
Val4 = 1 << 3
End Enum

As it "tells" me Val1 is the 0 bit, Val2 is the 1 bit, Val3 is the 2 bit,
Val4 is the 3 bit...

Hope this helps
Jay

"Eric Goforth" <an*******@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
Hello,

I'm sure that anyone with VB.NET would be familiar with the msgbox parameter syntax:

Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
msg = "Do you want to continue?" ' Define message.
style = MsgBoxStyle.DefaultButton2 Or _
MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
title = "MsgBox Demonstration" ' Define title.
' Display message.
response = MsgBox(msg, style, title)

So I pass in something like

style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or

MsgBoxStyle.YesNo

And it knows that I want a message box with a Yes and a No button, an

exclamation point icon, and make the No button the default.

DefaultButton2 = 256, critical = 16, and YesNo = 4

When I do the style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical

Or MsgBoxStyle.YesNo, I see style = 276.

The "+" operator will work as well, but the Intellisense doesn't work when I do this.

I can't find this functionality of the "Or" operator documented

anywhere.
What I'm trying to do is something like:

Begin Pseudo code ================

Private Enum MyEnum
MyVal0=0
MyVal1=1
MyVal2=2
End Enum

Dim MyVar as MyEnum

If MyCriteria1= True Then
MyVar = MyVal0
End If

If MyCriteria2 True Then
MyVar = MyVar Or MyVal1
End If

If MyVar Was assigned to MyVal0 Then
'Do Something

If MyVar Was Assigned to MyVal1 Then
'Do Something

End Pseudo code ================

I can change MyEnum such that MyVal0 = 4, MyVal1 = 16, etc. and then do a If MyVar Mod MyVal1 = 0 then
MyVar -= MyVal1

If MyVar Mod MyVal0 = 0 then
'Do something

'Go to the next smallest MyVal

Any idea how the messagebox function does it?

Thanks,
Eric


Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.