Results 1 to 4 of 4

Thread: Error Handling

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Cairo, Egypt
    Posts
    126

    Error Handling

    Hi All;
    I put the On Error Statment and write the error handling but the error still apeare when I click the cancel button in the common dialouge box. This is my code for this.

    Private Sub Command1_Click()
    On Error GoTo ErrorHandler

    CommonDialouge1.CancelError = True
    CommonDialouge1.DialogTitle = "Save Playlist File"
    CommonDialouge1.Filter = "All Files (*.*)|*.*|Text (*.txt)|*.txt"
    CommonDialouge1.FilterIndex = 2
    CommonDialouge1.flags = cdlOFNExplorer Or cdlOFNLongNames Or cdlOFNPathMustExist Or cdlOFNHideReadOnly
    CommonDialouge1.FileName = ""
    CommonDialouge1.ShowSave

    If Trim(CommonDialouge1.FileName) = "" Then
    Exit Sub
    End If

    ErrorHandler:
    Select Case Err.Number
    Case cdlCancel
    CommonDialouge1.FileName=""
    Resume Next
    End Select
    End Sub

  2. #2
    Addicted Member big_k105's Avatar
    Join Date
    May 2003
    Location
    North Dakota
    Posts
    195
    the only think i can see is your missing the : after this On Error GoTo ErrorHandler

    you have:
    VB Code:
    1. On Error GoTo ErrorHandler

    should be:
    VB Code:
    1. On Error GoTo ErrorHandler:

    and you need to have an exit sub in there that is used everytime not jst when CommonDialouge1.FileName = "".

    Do you get the same error as you did before you put in the error handler. or do you get a different one

    hope that helps
    Last edited by big_k105; Jun 10th, 2003 at 01:08 PM.

  3. #3
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: Error Handling

    Originally posted by Bobbo70
    Hi All;
    I put the On Error Statment and write the error handling but the error still apeare when I click the cancel button in the common dialouge box.
    no entiendo ..

    it should raise an error if you click cancel. looking at your code it seems that you realize this tho. please help me understand by rephrasing your question.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    You need an exit sub before the error handler. Without explicitly telling the sub to exit, execution will proceed right on into the error handler whether you have an error or not.

    I guess I'm unclear on whether that will solve your particular problem, but if that's not the problem, and you don't make this change, you will have further problems with that code.
    Last edited by Shaggy Hiker; Jun 10th, 2003 at 01:42 PM.

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