Solved

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

Posted on 2014-11-24
2
130 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

617 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