Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 135
  • Last Modified:

opendiagog1 generates an error if you hit cancel in vb.net

I use a opendialog control I can upload a picture   my question is when a user click cancel instead of ok for opendialog it bombs out on this line  pic = New Bitmap(OpenFileDialog1.FileName) I am clueless i've tryed a few tricks don't want to use On error resume next if there were just a way to just have nothing happen when user clicks cancel

 Public Sub uploadMLB()

        Dim path As String = "c:\My Pictures\"
        Dim pic As Image
        OpenFileDialog1.ShowDialog()
        pic = New Bitmap(OpenFileDialog1.FileName)
        If Sportscode = "AA" Then
            picnflplayer.Image = pic
            picnflplayer.Visible = True

        Else
            Exit Sub
            btnuploadpic.Text = "Save"
        End If

    End Sub

Open in new window

0
powerztom
Asked:
powerztom
1 Solution
 
AndyAinscowCommented:
You need to test the result of the ShowDialog.

If (MyDialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then
put your code for the new bitmap and other things here
End if
0
 
powerztomAuthor Commented:
AndyAinscow: THANK YOU MY FRIEND I WAS BATTLEING IT FOR AN HOUR THEN YOU STEPPED IT SIMPLE BUT EXFFECT THANKS ANDY.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now