Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a form which, when data is entered in certain textboxes, produces a file path to retrieve a .gif file for a picturebox.

 

My problem is - how can I get a messagebox to say "File not found" if the file does not exist in that directory or if the data placed in the textboxes is incorrect thereby giving a wrong file path?

 

Everything I try comes back with a debugging message.

 

Help would be much appreciated. Thanks.

Posted

This should solve your problem, just use Try and Catch, so if there is an error in the Try, then you can refer to the code in Catch, you shall see my son:

 

'This is where you enter the code to get the .gif that gives ya trouble

Try
    Dim strPath As String

    strPath = "The path of the .gif I want to use.gif"
    PictureBox1 = PictureBox1.FromFile(strPath)
Catch
   MessageBox.Show("That path is false")
End Try

"Reality is fake, Dreams are for real"
Posted

Thank you, it works perfectly.

 

Will I ever understand all of this? I am enjoying the challenge but it gets so frustrating sometimes!

 

Once again - thanks for your assistance

Posted

That is the sleezy method of doing it

 

and if you're in for programming in .NET the right way you should make use of the namespaces that .NET provides

 

 

this is the real way of doing it

 

 

If System.IO.File.Exists(Me.txtPath.text) Then
           'Returned file path is true then proceed on
           Me.Picture1.Image = PictureBox1.FromFile(Me.txtPath.text)
       Else
           'If Returned file path is false then Prompt user
           MessageBox.Show("File Does not exist!", "File not found.", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...