Hi David,

You should reset your error trap immidiatedly after it's relevant use. In this case, it should be reset after "Open File".

If you want an error trap around "Print #5" and "Close File", create another error trap for each of them.

The second problem is that you attempt to close the file even if the opening erred, throwing a new runtime error. This may be what you're experiencing.

I've rewritten your code to this:

Sub LogMessage
        Dim TempText as String

        OnError goto ErrorHandler
        Open File ApplicationDirectory$() + "MVMMapInfo.LOG" For Append As #5
        OnError Goto 0

        Print #5, CurDate() + " " + " " + Time(24) + " " + Message
Close File #5
        Exit Sub

ErrorHandler: TempText = "Error in LogMessage: " + Err() + " " + Error$() + Message
        Print TempText
        Call LogDebug(TempText) 
        Exit Sub

End Sub

Lastly, you should always apply the "Charset" subclause when openijng files, since the default is a DOS CodePage, not Windows ANSI. E.g. Charset(WindowsLatin1)

HTH

Best regards / Med venlig hilsen
Lars I. Nielsen
GisPro



[EMAIL PROTECTED] wrote:
Is OnError unable to trap some kind of errors?

I have the following code:

'****************************************************************************
' LogMessage: Writes messages to a log file
'
Sub LogMessage

        OnError goto ErrorHandler
        Open File ApplicationDirectory$() + "MVMMapInfo.LOG" For Append As #5
        Print #5, CurDate() + " " + " " + Time(24) + " " + Message
Close File #5 OnError Goto 0

        Exit Sub

ErrorHandler: Close File #5 TempText = "Error in LogMessage: " & Err() & " " & Error$() & Message
        Print TempText
        Call LogDebug(TempText) 
        OnError goto 0
        Exit Sub

End Sub


However, my application occasionally crashes at the line after the OnError 
line, i.e.
Open File ApplicationDirectory$() + "MVMMapInfo.LOG" For Append As #5

The error is:

"Cannot access file MVMMapInfo.LOG"

Has anyone seen this happen before where the OnError trap is ignored (or at least I assume it is being ignored...) I don't have the MVMMapInfo.LOG file open at the time the error occurs, though it is possible that the application might not have closed it properly at it's last attempt.

Thanks,

Dave
_______________________________________________
MapInfo-L mailing list
[email protected]
http://www.directionsmag.com/mailman/listinfo/mapinfo-l

_______________________________________________
MapInfo-L mailing list
[email protected]
http://www.directionsmag.com/mailman/listinfo/mapinfo-l

Reply via email to