0

I have the following code in Globals.bas:

Public Const strErrorLog = "log.log"

    Public Sub WriteLog(ByVal strMess As String, ByVal ErrLog As String)
    Dim intLogFile As Integer

    On Error GoTo GenErr
        'Print the path of the log file
        If ErrLog <> "" Then
            ' save errors to a text file
            intLogFile = FreeFile
            Open ErrLog For Append As #intLogFile
            Print #intLogFile, Str(Now) & " " & strMess
            Close intLogFile
        End If

        Exit Sub
    GenErr:
        Select Case ShowError(Err, Error$ & " in WriteLog", strErrorLog)
            Case vbAbort: Exit Sub: Case vbIgnore: Resume Next: Case vbRetry: Resume
        End Select

    End Sub

How do I get the full path of the log file as the application does not seem to be writing to the correct place.

w0051977
  • 15,099
  • 32
  • 152
  • 329
  • 1
    That relative path is relative to what? – GSerg Apr 07 '15 at 08:13
  • If ErrLog ="", nothing it's done? – Morcilla de Arroz Apr 07 '15 at 08:22
  • @GSerg, it is relative to the executeable on the current live server. However, this does not seem to be the case on the server I am moving it to. – w0051977 Apr 07 '15 at 08:33
  • You will have to give us enough information to reproduce the problem, else we can't help. See this for guidance: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – Jean-François Corbett Apr 07 '15 at 09:03
  • 2
    Relative paths are relative to the current directory. It is not necessarily the folder with the exe. See http://stackoverflow.com/q/12423824/11683 and http://stackoverflow.com/q/154299/11683. – GSerg Apr 07 '15 at 09:09
  • I wouldn't be surprised to find CD defaulted to App.Path but the log files being created in the VirtualStore folder of each user. – Bob77 Apr 07 '15 at 12:52
  • Is there code that builds the `ErrLog` parameter? What are you passing into the method? – jac Apr 07 '15 at 20:43
  • This could be anything. I suspect, however, that there's some code in the application that reads a registry value that has the path to the log file. You need to step through the code that writes to a log file, and ask more specific questions if you can't see what it does. – BobRodes Apr 08 '15 at 04:08
  • @Bob77 VB6 has no concept of VirtualStore folders, and the `Open` operator has no idea that it's going to open a log file as opposed to some other type of file. – GSerg Apr 08 '15 at 08:10
  • @jac `Public Const strErrorLog = "log.log"` – GSerg Apr 08 '15 at 08:10
  • @BobRodes `Public Const strErrorLog = "log.log"` – GSerg Apr 08 '15 at 08:10
  • Windows maintains VirtualStore folders on a per-user basis. There is nothing VB6-specific about this. When a file is opened for writing within a protected folder Windows virtualizes it unless the process was marked Vista-aware or runs elevated. Your program is oblivious to this, as intended with most appcompat shims. – Bob77 Apr 08 '15 at 22:04

0 Answers0