MsgBox won't display

  • Thread starter Thread starter Ivan Jericevich
  • Start date Start date
I

Ivan Jericevich

In my code below at the line 'response' a blip sound is heard and the
program exits the sub -- No MsgBox is displayed. What am I doing wrong?

If nonNumberEntered = True Then

msg = "Enter numbers only"

style = MsgBoxStyle.OkOnly

title = "ERROR in cast"

MsgBox(msg, style, title)

response = MsgBox(msg, style, title)

If response = MsgBoxResult.Yes Then

Exit Sub

Else

End If

e.Handled = True

End If
 
Private Sub DisplayMesageBox(ByVal bNumbersEntered As Boolean)
If bNumbersEntered = False Then
MessageBox.Show("Enter numbers only", "ERROR in cast",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub

Call it by:

DisplayMesageBox(False)

I hope this helps,

Newbie Coder
 
Ivan said:
In my code below at the line 'response' a blip sound is heard and the
program exits the sub -- No MsgBox is displayed. What am I doing wrong?

If nonNumberEntered = True Then

msg = "Enter numbers only"

style = MsgBoxStyle.OkOnly

title = "ERROR in cast"

MsgBox(msg, style, title)

response = MsgBox(msg, style, title)

If response = MsgBoxResult.Yes Then

Exit Sub

Else

End If

e.Handled = True

End If
There could be a number of problems with the example you've given. In
particular, the "Else" seems to be in the wrong place, so I can only
guess you've incorrectly pasted your example.

To simplify the MsgBox, maybe just use the following (watch for wrapping!) -

If MsgBox("Enter numbers only", MsgBoxStyle.OkOnly, "Error in Cast") =
MsgBoxResult.Yes Then
Exit Sub
End If


Hope this helps!

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
Sorry.

Left a little off the last post

Private Sub DisplayMesageBox()
MessageBox.Show("Enter numbers only", "ERROR in cast",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Sub

Simple call:

DisplayMesageBox()

I hope this helps,

Newbie Coder
 
Why do you need a MessageBoxResult of YES in an OK only MessageBox?

How will that ever be called because there is no YES button?

I hope this helps,

Newbie Coder.
 
Sorry, after re-reading your OP, I should have suggested the following -

If nonNumberEntered = True Then
MsgBox("Enter numbers only", MsgBoxStyle.OkOnly, "Error in Cast")
Exit Sub
Else
e.Handled = True
End If


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
Newbie said:
Why do you need a MessageBoxResult of YES in an OK only MessageBox?

How will that ever be called because there is no YES button?

I hope this helps,

Newbie Coder.
I corrected that. :-)

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
Ivan,
As the others suggest I normally use MessageBox.Show instead of MsgBox,
however I don't see that is a problem here!

The first problem I see is you are call MsgBox twice, which is annoying at
best.
MsgBox(msg, style, title)
response = MsgBox(msg, style, title)

Another problem that I noticed is the Message Box is not visible if I
attempt to single step the code under Vista x64. I needed to use Alt+Tab (or
use Flip 3D) to find the Message Box & show it. However I suspect this is
more an artifact of not having a window shown when I tested the code rather
then a Vista specific problem.

One of the reasons I prefer MessageBox.Show over MsgBox is that I have
control over which window "owns" the message box.

MessageBox.Show(Me, msg, title, MessageBoxButtons.OK)
 
Doh! (clicked send too soon).

Can you give more details on the type of application that the code appears
in: (Windows Forms, Windows Service, Web Form, Web Service) Plus details of
where the code is being called, such as what event is being handled when you
call your routine...
 
Ivan,

I would at least remove one of those showings of the messagebox.

MsgBox(msg, style, title)

I never use this one, however when I tested it, it gave strange behaviour.
Different in step by step (twice displayed) than while running (once
displayed).

Cor
 
Back
Top