Msgbox parameter Or operator questions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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 said:
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.
 
* =?Utf-8?B?RXJpYyBHb2ZvcnRo?= said:
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
 
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 said:
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.
 
Nice! :-)

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

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

Please respond to the newsgroup,
so all can benefit
 
Back
Top