MapInfo Pro

Expand all | Collapse all

Mapinfo crashes when trying to print to txt file

  • 1.  Mapinfo crashes when trying to print to txt file

    Posted 02-14-2019 19:12
    I want to log the text from a message window in a mapbasic script to a txt file but the program now crashes.

    Print ProcessThese.FullPath
    Open file "D:\4_RefreshMB.txt" for output as #1
    Print #1, ProcessThese.FullPath
    Close File #1
    Run Command CmdString

    enter image description here

    Problem signature: Problem Event Name: BEX Application Name: Mapinfow.exe Application Version: 12.5.0.206 Application Timestamp: 54bd32f4 Fault Module Name: MSVCR110.dll Fault Module Version: 11.0.50727.1 Fault Module Timestamp: 5011aa2a Exception Offset: 0009e1d1 Exception Code: c0000417 Exception Data: 00000000 OS Version: 6.1.7601.2.1.0.272.7 Locale ID: 3081 Additional Information 1: 3a04 Additional Information 2: 3a0491f107d8a808063562f7a7e91ce4 Additional Information 3: cb13 Additional Information 4: cb1337f25bf49f1acbe672c17d32b428 Read our privacy statement online: http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409 If the online privacy statement is not available, please read our privacy statement offline: C:\Windows\system32\en-US\erofflps.txt

    The code runs fine without the open/close file commands but I want to have a log file.


    ------------------------------
    George Corea
    Mangoesmapping
    ------------------------------


  • 2.  RE: Mapinfo crashes when trying to print to txt file

    Posted 02-14-2019 19:57
    Hi George,

    Perhaps try assigning ProcessThese.FullPath to a variable first; e.g:
    sFullPath = ProcessThese.FullPath
    Print #1, sFullPath

    You will need to declare the variable first (at the beginning of the program):
    Dim sFullPath As String

    Also please note the following:
    * The "Run Command CmdString" line is unrelated to what you're trying to do here (but don't delete it - it is still a required part of your code)
    * I understand from your previous post that this code is in a loop.  Whilst what you have done should work, it would be better to execute the 'Open file "D:\4_RefreshMB.txt" for output as #1' statement just before the start of the loop, then close the file at the end of the loop.

    ------------------------------
    James Nolet
    Dooley Mitchell & Morrison Pty Ltd
    ------------------------------



  • 3.  RE: Mapinfo crashes when trying to print to txt file

    Posted 02-14-2019 21:34
    Thanks. I tried this but it still crashes.

    ------------------------------
    George Corea
    Mangoesmapping
    ------------------------------



  • 4.  RE: Mapinfo crashes when trying to print to txt file

    Pitney Bowes
    Posted 02-15-2019 12:25
    Hi. What is the value of ProcessThese.FullPath? Any chance that ProcessThese is not assigned? If you print to the Message Window, instead of a file, do you see what you would expect to see? Does the output file get created?

    ------------------------------
    John Teague
    PITNEY BOWES SOFTWARE, INC
    Troy NY
    ------------------------------



  • 5.  RE: Mapinfo crashes when trying to print to txt file

    Pitney Bowes
    Posted 02-15-2019 12:48
    Also, you can add an error handler which might help here.
    E.g.,
    sub main
    onerror goto ErrorTrap
    ...
    Done:
    Exit Sub
    ErrorTrap:
    print "Main: " + Str$(err()) + ": " + Error$()
    Resume next
    End Sub

    ------------------------------
    John Teague
    PITNEY BOWES SOFTWARE, INC
    Troy NY
    ------------------------------



  • 6.  RE: Mapinfo crashes when trying to print to txt file

    Posted 02-17-2019 21:04
    I added this error capture but it still crashes.

    ProcessThese.FullPath is simply an in memmory file that it takes the value in the column FullPath from to create a list. The full code is part of this question as I inherited this code base without any notes and we found that it's crashing in some steps. So I wanted to write the messages that currently write just to the message window to a text file so that I can easily see where the error is happening -usually causing MI to crash with no error report about 45 mins after it starts to execute.

    ...but the (simple) addition of code to log to a txt file is now causing mapinfo to crash before it starts executing...

    ------------------------------
    George Corea
    Mangoesmapping
    ------------------------------



  • 7.  RE: Mapinfo crashes when trying to print to txt file

    Posted 02-17-2019 21:58
    Hi George,

    I'm probably on the wrong track, but am just wondering about the following questions:

    Can you see if anything prints to the message window before MapInfo crashes?  I would expect at least one FullPath string to be printed before the crash, if it is the log file causing the error.
    Have you tried a different path for the log file?
    Can you give an example of the strings within the FullPath field?  Are there any invalid characters in any of the records?

    ------------------------------
    James Nolet
    Dooley Mitchell & Morrison Pty Ltd
    ------------------------------



  • 8.  RE: Mapinfo crashes when trying to print to txt file

    Posted 02-18-2019 02:36
    Here is the log procedure I normally when having to use logging in my MapBasic application:

    Sub DEBUGWriteToFile(ByVal sMessage As String)
    Dim nErr As Integer
    OnError GoTo ErrorOccured

    'I'm using a variable file set elsewhere but you can hardcode it as shown below
    'Open File msDebugFile
    Open File PathToDirectiory$(TempFileName$()) & "logfile.txt"
       For Append As #975
       CharSet SystemInfo(SYS_INFO_CHARSET)

    Print #975, Time(24) & " " & sMessage
    Close File #975

    Exit Sub
    '-------------------------
    ErrorOccured:
       nErr = Err()
       If nErr = 825 Then
          Resume 0
       Else
          Print "Error: " & nErr & ": " & Error$() & " DEBUGWriteToFile: " & sMessage
       End If

    End Sub

    I wonder if it can be connected to the location of your log file. Have you tried specifying a path to your TEMP folder as I have done above?

    ------------------------------
    Peter Horsbøll Møller
    Pitney Bowes
    ------------------------------