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

MsgBox won't display

P: n/a
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
Jan 2 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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
Jan 2 '07 #2

P: n/a
Ivan Jericevich wrote:
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.
Jan 2 '07 #3

P: n/a
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
Jan 2 '07 #4

P: n/a
ShaneO wrote:
Ivan Jericevich wrote:
>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?
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.
Jan 2 '07 #5

P: n/a
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.
Jan 2 '07 #6

P: n/a
Newbie Coder wrote:
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.
Jan 2 '07 #7

P: n/a
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)

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Ivan Jericevich" <iv**@oberon.co.zawrote in message
news:%2*****************@TK2MSFTNGP03.phx.gbl...
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

Jan 2 '07 #8

P: n/a
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...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Ivan Jericevich" <iv**@oberon.co.zawrote in message
news:%2*****************@TK2MSFTNGP03.phx.gbl...
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

Jan 2 '07 #9

P: n/a
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
"Ivan Jericevich" <iv**@oberon.co.zaschreef in bericht
news:%2*****************@TK2MSFTNGP03.phx.gbl...
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


Jan 2 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.