Results 1 to 9 of 9

Thread: [RESOLVED] 'On Error GoTo MockErr1' Not Working

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Resolved [RESOLVED] 'On Error GoTo MockErr1' Not Working

    I've made a procedure that creates a directory structure according to a textfile. It works perfectly fine, except there are some files that it can't create (long story).

    I've built an error handler to record which files can't be made and then to continue building the rest of the files, but the problem is that when an error occurs the first time, it is recorded fine but the next time an error occurs, VB
    pops up a runtime error instead of going to MockErr1.
    How can I solve this so that it will always go to MockErr1?

    Here's part of the code
    VB Code:
    1. Private Sub MakeIt()
    2. On Error GoTo MockErr1 'This is for stubborn filenames
    3.             Open App.Path & "\Mock Systems\" & lstTrees.Text & "\" & Trees(i) For Output As #90 'Create the file
    4.             Print #90, "Blah"
    5.             Close #90
    6. Exit Sub
    7. MockErr:
    8. MsgBox Err.Description
    9. MockErr1:
    10. 'Error occured during construction of dir structure
    11. Open App.Path & "\Mock Systems\" & lstTrees.Text & "\Err.txt" For Append As #78
    12. Print #78, "'" & Err.Description & "' {" & Err.Number & "}" & " [" & Trees(i) & "]"
    13. Close #78
    14. Err.Clear
    15. GoTo DoStats
    16. End Sub
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: 'On Error GoTo MockErr1' Not Working

    where this is defined in your procedure...
    VB Code:
    1. GoTo DoStats
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: 'On Error GoTo MockErr1' Not Working

    Well actually the code I posted is just an extract from a loop.
    DoStats is at the bottom of the loop, here it is:
    VB Code:
    1. On Error GoTo MockErr1 'This is for stubborn filenames
    2.             Open App.Path & "\Mock Systems\" & lstTrees.Text & "\" & Trees(i) For Output As #90 'Create the file
    3.             Close #90
    4.         End If
    5.     End If
    6. DoStats:
    7. Progress.Value = i
    8. PercentDone = i / UBound(Trees) * 100
    9. lblStatus.Caption = Left$(PercentDone, InStr(1, PercentDone, ".") + 2) & "% Built"
    10. DoEvents
    11.  
    12. Next i
    13.  
    14. Exit Sub
    15. MockErr:
    16. MsgBox Err.Description
    17. MockErr1:
    18. 'Error occured during construction of dir structure
    19. Open App.Path & "\Mock Systems\" & lstTrees.Text & "\Err.txt" For Append As #78
    20. Print #78, "'" & Err.Description & "' {" & Err.Number & "}" & " [" & Trees(i) & "]"
    21. Close #78
    22. Err.Clear
    23. GoTo DoStats
    24. End Sub
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  4. #4
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    266

    Re: 'On Error GoTo MockErr1' Not Working

    May be second run time error occur due to open stmt beingh used in error handler...due to which it is not going to handle it properly but throwing runtime error.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: 'On Error GoTo MockErr1' Not Working

    Nope. I Changed the 'MockErr1' to Close #90 but I still get the error.
    The error I get is 'Path Not Found' and that is the error I want to trap, so there is nothing wrong with my coding, the problem is that it is only trapping the error the first time it occurs, after that it just shows the error instead of going to MockErr1
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  6. #6
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: 'On Error GoTo MockErr1' Not Working

    Try changing your code to Resume DoStats instead of GoTo. That should clear the current error condition (no need to do Err.Clear) and jump to DoStats.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: 'On Error GoTo MockErr1' Not Working

    Pete, you genius, you've done it!

    Apparently "You must spread some Reputation around before giving it to pnish again."
    But it's the thought that counts
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  8. #8
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: 'On Error GoTo MockErr1' Not Working

    Glad to help. Thanks for the thought...
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: 'On Error GoTo MockErr1' Not Working

    Anytime
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

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