Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error Trapping (VB6)

    I've included error trapping in my start form.

    I trapped two errors - 71 & 76

    At the start of my code before the declarations I added:


    <pre> On Error GoTo ErrHandler</pre>


    Code starts here......................


    At the end of the code I added:

    <pre>ErrHandler:
    Me.MousePointer = vbDefault

    If Err = 76 Or 71 Then MsgBox "You Must Exit This Program Now, " & vbCrLf & _
    "Please Insert The Installation Disk Into Drive D:" & vbCrLf & _
    "And Re-Run This Program.... " & vbCrLf & _
    vbCrLf & "Required Files Need To Be Loaded Before This" & vbCrLf & _
    "Program Can Run.", vbCritical, "Error" & " " & _
    Err.Number & " " & Err.Description
    Me.Text1 = ""
    Me.Text1.Refresh
    Me.Label1.Caption = ""
    Me.Label1.Refresh</pre>


    When running the program, the err trapping returns the msgbox and error No 0 evry time it is run, whether or not the disk
    or file exists.

    Can any-one see where the problem lies ?

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Error Trapping (VB6)

    Do you have an Exit Sub (or Exit Function) before the error handler. It sounds to me as though you may be running off the end of your code into the error handling code.

    Also I think that the line "If Err=76 or 71" may not be doing what you think! I would suggest replacing it with...
    <font face="Georgia">Select Case Err.Number
    Case 71,76
    <font color=448800> ' put your code here </font color=448800>
    Case Else
    <font color=448800> ' put your default error handling code here </font color=448800>
    End Select<font face="Georgia">

    StuartR

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Trapping (VB6)

    Stuart

    Thanks for the help.
    There is no Exit sub or function before the errHandler. (should there be ?)

    I now have this as errHandler, does it look ok ?

    <pre>ErrHandler:
    Me.MousePointer = vbDefault

    Select Case Err.Number

    Case 71, 76
    MsgBox "You Must Exit This Program Now, " & vbCrLf & _
    "Please Insert The Installation Disk Into Drive D:" & vbCrLf & _
    "And Re-Run This Program.... " & vbCrLf & _
    vbCrLf & "Required Files Need To Be Loaded Before This" & vbCrLf & _
    "Program Can Run.", vbCritical, "Error" & " " & _
    Err.Number & " " & Err.Description
    Me.Text1 = ""
    Me.Text1.Refresh
    Me.Label1.Caption = ""
    Me.Label1.Refresh
    Case 0
    'Do Nothing
    Case Else
    MsgBox " Error" & " " & Err.Number & " " & Err.Description
    End Select
    End Sub</pre>


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Error Trapping (VB6)

    You only want to go into the error handler part if a real error occurred, that's why you should have Exit Sub immediately before it. Checking for Err.Number = 0 is superfluous then (although it doesn't hurt). So:

    - Insert a line Exit Sub immediately above ErrHandler:
    - Remove Case 0

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Trapping (VB6)

    Like : -

    <pre> Me.cmdArchiveOpen.Enabled = True
    Me.cmdImage.Enabled = True
    Me.cmdInfo.Enabled = True
    Me.cmdShowFiles.Enabled = True

    Me.MousePointer = vbDefault
    Label1.Caption = ""
    Label1.Refresh
    lblText.Caption = "Designed By Dave Willett (2003).................."
    TheX = pbScrollBox.ScaleWidth
    Exit Sub
    ErrHandler:
    Me.MousePointer = vbDefault

    Select Case Err.Number

    Case 71, 76
    MsgBox "You Must Exit This Program Now, " & vbCrLf & _
    "Please Insert The Installation Disk Into Drive D:" & vbCrLf & _
    "And Re-Run This Program.... " & vbCrLf & _
    vbCrLf & "Required Files Need To Be Loaded Before This" & vbCrLf & _
    "Program Can Run.", vbCritical, "Error" & " " & _
    Err.Number & " " & Err.Description
    Me.Text1 = ""
    Me.Text1.Refresh
    Me.Label1.Caption = ""
    Me.Label1.Refresh
    Case Else
    MsgBox " Error" & " " & Err.Number & " " & Err.Description
    End Select
    End Sub</pre>


    If so, Thanks

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Error Trapping (VB6)

    Yes <img src=/S/yep.gif border=0 alt=yep width=15 height=15>

Posting Permissions

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