How to handle YesNoCancel in vb.net project?

I have always used this code to handle a Yes or No answer:

        If MsgBox(psWork1, MsgBoxStyle.YesNo, "Clear Verify File?") = vbYes Then
            sPassParam0 = "ShpVerInit"
        Else
            sPassParam0 = "ShpVerAppend"
        End If

This was easy, because if it was not "vbYes", then it obviously had to be "No".  But now I need to add the Cancel option, i.e. MsgBoxStyle.YesNoCancel, but I don't know how to do the If-Then syntax with this 3rd option.  If they choose "Cancel", I want to Exit Sub, but what is the proper syntax in this case?  TIA
LVL 3
sasllcAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi sasllc;

This should give you what you need.

Dim optionSelected As MsgBoxResult = MsgBox(psWork1, MsgBoxStyle.YesNoCancel, "Clear Verify File?")

If optionSelected = vbYes Then
    sPassParam0 = "ShpVerInit"
ElseIf optionSelected = vbNo Then
    sPassParam0 = "ShpVerAppend"
Else
    sPassParam0 = "ShpVerCanceled"
End If

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wayne Taylor (webtubbs)Commented:
Use a Select Case statement...

Select Case MessageBox.Show("Clear Verify File?", "", MessageBoxButtons.YesNoCancel)
    Case DialogResult.Yes
        'do something
    Case DialogResult.No
        'do something else
    Case DialogResult.Cancel
        Exit Sub
End Select

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.