error label and for next loop

Discussion in 'Questions (Windows Mobile)' started by Cableguy, May 22, 2007.

  1. Cableguy

    Cableguy Expert Licensed User


    I have an Error Label inside a for next loop, and when an error is trapped the error label is called but the for next loop is not exited and becomes an endless loop...

    Sub MySub

    errorlabel (error)

    for x = 0 to 49
    D Something
    next x

    msgbox("file was not created!!",,cMsgBoxOK,cMsgBoxExclamation)

    End Sub
    How can I exit the loop when the error is trapped?
    I've tryed Exit and Return with no success!!
  2. specci48

    specci48 Well-Known Member Licensed User

    I tested your code and tried even a "do while" loop.
    Its a strange behaviour! :confused:
    Sometimes it seems to work fine, sometimes the application seems to hang, even on the desktop just executing a "do nothing loop" with only 40 repeats.
  3. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I think that perhaps you need to have a variable inside the For Next loop that is examined each time around the loop. If the error is caught then the variable can be set and this in turn causes the loop to be broken, personally I would use the Break command to exit the loop.

  4. Erel

    Erel Administrator Staff Member Licensed User

    Can you upload a simple program that shows the problem?
  5. Cableguy

    Cableguy Expert Licensed User

    Thanks for your help,It seems the problem is my sub I had an open conection to a file and when the error was trapped the file wasn't closed causing the endless loop...Now it works fine
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice