Solved

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

Posted on 2014-11-24
2
121 Views
Last Modified: 2014-11-24
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
Comment
Question by:powerztom
2 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 40462776
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
 

Author Closing Comment

by:powerztom
ID: 40462809
AndyAinscow: THANK YOU MY FRIEND I WAS BATTLEING IT FOR AN HOUR THEN YOU STEPPED IT SIMPLE BUT EXFFECT THANKS ANDY.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now