CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Error Trap

  1. #1

    Question Error Trap

    this is code i am useing in my program to load a picture if for some reason the picture is deleted or moved the program will give a error and close down what i need for this to do is have a error trap where if the picture is deleted or moved it will show another picture in the picture box

    Code:
    Private Sub Form_Load()
      Close
      arb = 0
      'cd2.Filter = "Image Files (*.*)|*.*"
    Filename$ = cd2.Filename
    txtpictures.Text = Filename$
    Recordlen = Len(person)
    Filenum = FreeFile
    Open "c:\program files\bondsman\info.dat" For Random As Filenum Len = Recordlen
    If carryover > 0 Then Currentrecord = carryover Else Currentrecord = 1
    Lastrecord = FileLen("c:\program files\bondsman\info.dat") / Recordlen
    If Lastrecord = 0 Then
    Lastrecord = 1
    End If
    ShowCurrentrecord
    frmPicture.open.Picture = LoadPicture(txtpictures.Text)
    End Sub


    thank you for any help you can give

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Error Trap

    I'm not sure what you are doing when you're reading the file, but, here is a standard Error Trap. Sorry if I couldn't test it. It was from memory.

    Code:
    Option Explicit
    
    Private Sub Form_Load()
      On Error GoTo ErrorSub
        ShowCurrentrecord
        frmPicture.open.Picture = LoadPicture(txtpictures.Text)
        Exit Sub ' Exits if NO ERROR
    ErrorSub:
        frmPicture.open.Picture = "default"
        On Error GoTo 0
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Sep 2006
    Posts
    17

    Re: Error Trap

    Instead of using an error trap for this I think you would be better off checking to see if the file exists before trying to open it. Then, check to see if the backup file exists before you open it. If you can't open either, display a message somewhere that the file was unavailable.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured