Solved

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

Posted on 2014-11-24
2
118 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
Comment Utility
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
Comment Utility
AndyAinscow: THANK YOU MY FRIEND I WAS BATTLEING IT FOR AN HOUR THEN YOU STEPPED IT SIMPLE BUT EXFFECT THANKS ANDY.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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 …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

11 Experts available now in Live!

Get 1:1 Help Now