MessageBox Question

M

MadCrazyNewbie

Hey Group,

Sorry to be a pain again but i have the following code:

If MessageBox.Show("Are Your Sure You Want To Send This Email?", "Are Your
Sure You Want To Send This Email?", MessageBoxButtons.OKCancel) Then
Try
SmtpMail.SmtpServer = txtSMTP.Text
Dim Message As MailMessage
Message = New MailMessage()
Message.From = txtFrom.Text
Message.To = txtTo.Text
Message.Subject = "Excellence.Net - Email"
Message.Body = txtMessage.Text
Message.BodyFormat = MailFormat.Text
SmtpMail.Send(Message)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End If

All is ok - message pops up and asks yes or cancel, however if i click
Cancel it still send the message? anybody kindly point me in the right
direction?

Ta
MCN
 
A

Armin Zingler

MadCrazyNewbie said:
If MessageBox.Show("Are Your Sure You Want To Send This Email?", "Are
Your Sure You Want To Send This Email?", MessageBoxButtons.OKCancel)
Then
Try
SmtpMail.SmtpServer = txtSMTP.Text
Dim Message As MailMessage
Message = New MailMessage()
Message.From = txtFrom.Text
Message.To = txtTo.Text
Message.Subject = "Excellence.Net - Email"
Message.Body = txtMessage.Text
Message.BodyFormat = MailFormat.Text
SmtpMail.Send(Message)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End If

All is ok - message pops up and asks yes or cancel, however if i
click Cancel it still send the message? anybody kindly point me in
the right direction?

Enable Option Strict.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
M

MadCrazyNewbie

Armin,

I`ve enabled Options Strict On but now I get a message saying:

D:\Live Projects\Excellence.Net\EmailForm.vb(240): Option Strict On
disallows implicit conversions from 'System.Windows.Forms.DialogResult' to
'Boolean'.

on
If MessageBox.Show("Are Your Sure You Want To Send This Email?", "Are Your
Sure You Want To Send This Email?", MessageBoxButtons.OKCancel) Then

Any Ideas?

Cheers
MCN
 
A

Armin Zingler

MadCrazyNewbie said:
If MessageBox.Show("Are Your Sure You Want To Send This Email?",
"Are Your Sure You Want To Send This Email?",
MessageBoxButtons.OKCancel) Then
[...]

All is ok - message pops up and asks yes or cancel, however if
i click Cancel it still send the message? anybody kindly point me
in the right direction?

Enable Option Strict.


I`ve enabled Options Strict On but now I get a message saying:

D:\Live Projects\Excellence.Net\EmailForm.vb(240): Option Strict
On disallows implicit conversions from
'System.Windows.Forms.DialogResult' to 'Boolean'.

on
If MessageBox.Show("Are Your Sure You Want To Send This Email?", "Are
Your Sure You Want To Send This Email?", MessageBoxButtons.OKCancel)
Then

Any Ideas?

The error message says everything you need:
- The return type of the show function is System.Windows.Forms.DialogResult.
- The If statement needs a boolean expression.
=> You have to compare the return value to one of the possible values to get
a boolean expression.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
C

Cor Ligthert

Hi Simon,

When you type the = the enum answer comes direct.

If MessageBox.Show("Are Your Sure You Want To Send This Email?", "Are Your
Sure You Want To Send This Email?", MessageBoxButtons.OKCancel) =
DialogResult.OK Then


Cor
 
S

Scott M.

You are testing if your messagebox returns True (boolean) while you are
using OK and Cancel buttons, neither of which return true.
 
J

Jay B. Harlow [MVP - Outlook]

MCN,
In addition to the other comments.
If MessageBox.Show("Are Your Sure You Want To Send This Email?", "Are Your
MsgBox(ex.ToString)

I would use one or the other version of MessageBox, not both within a single
program, so as to avoid incompatible parameters...

Of course if you upgraded an existing program and are slowing migrating to
one version than that's understandable... I would consider shadowing the
VB.MsgBox with my own, that has the ObsoleteAttribute on it, so as to
identify all the ones that I need to change... In addition to the
ObsoleteAttribute I would simply call the normal VB.MsgBox...

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top