Results 1 to 7 of 7

Thread: How to edit my log text file?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Saudi Arabia, Gulf side, Qatif
    Posts
    142

    Unhappy

    I am using open statement on the load event to log the user id and the pc id and the time user start my program and save these values in a text file for my auditting, my quistion is about logging the time user end my program and write the values after the line where it writes his logged on information in the same text file
    Hopefuly my quistion is clear, it is almost like alterring the Ini file but I beleive ther is an easy to do that with the text file.
    Regards
    '''''''''''
    The statement I use to log on loading the prog:
    Dim intChFile As Integer
    startupLogFileName = "Log Path"
    intChFile = FreeFile
    Open startupLogFileName For Append As #intChFile
    Print #intChFile, userid & " " & "Logon" & " " & " " & "From PC#:" & " " & pc_name & " " & "On" & " " & Format(Now, "general date")
    Close intChFile

    [Edited by maqmaq on 07-17-2000 at 08:49 AM]

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Location
    Vaxjo, Sweden
    Posts
    85
    You want the log-off info to be on the line after the log-on info and whe other stuff has been logged afterwards, right?
    Keep the string written to the log file on log-on in memory and search for it when you exit the program. Then insert the log off string there.

    //Anders
    Reality is what you make up when you can't handle your fantasies.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Saudi Arabia, Gulf side, Qatif
    Posts
    142
    That is exactly what I ma looking for, I can search for it but when I find it what is the code of writing the log off exactly after the line I found, would you please give any example in this regards
    I appreciate

  4. #4
    Lively Member
    Join Date
    Jul 2000
    Location
    Vaxjo, Sweden
    Posts
    85
    Try this:
    Code:
    Private Sub WriteToLog(strSearch As String, strLogItem As String, strLogFile As String)
    Dim lngLogFile As Long
    Dim lngTempFile As Long
    Dim strBuffer As String
    On Error Resume Next
    
      lngLogFile = FreeFile
      Open strLogFile For Input As #lngLogFile
      
      lngTempFile = FreeFile
      Open "c:\temp.log" For Output As #lngTempFile
      
      Do While Not EOF(lngLogFile)
        Line Input #lngLogFile, strBuffer
        If strBuffer = strSearch Then
          Print #lngTempFile, strLogItem
        End If
        Print #lngTempFile, strBuffer
      Loop
      Close #lngLogFile
      Close #lngTempFile
      
      Kill strLogFile
      FileCopy "c:\temp.log", strLogFile
    
    End Sub
    //Anders
    Reality is what you make up when you can't handle your fantasies.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Saudi Arabia, Gulf side, Qatif
    Posts
    142
    Anders
    Thanks for what you posted, any how I used a little defferent code and it works fine except that it will over write the second line of the found text, I hope you can help me to let writing after the found text, the code I used:
    '''''''''''''''''''''
    Stringsearch = "this is the search text"
    pathh = "c:\log.txt"
    Open pathh For Binary As #1
    Do While Not EOF(1)
    Line Input #1, stng
    If stng = Stringsearch Then
    Put #1, , vbEnter & "done"
    End If
    Loop
    Close #1
    ''''''''''''''''''''''
    The text file before implementing the code:
    '''''''''''''''''
    This is line one
    This is line two
    This is line three
    this is the search text
    This is line four
    this is line five
    ''''''''''''''''''
    The text file after implementing the code:
    ''''''''''''''''''
    This is line one
    This is line two
    This is line three
    this is the search text
    done is line four
    this is line five
    '''''''''''''''''''
    Any idea will be appreciated
    Regards


    [Edited by maqmaq on 07-18-2000 at 12:38 AM]

  6. #6
    Lively Member
    Join Date
    Jul 2000
    Location
    Vaxjo, Sweden
    Posts
    85
    Yea, I don't think it's possible to just insert a line of text like that. You must either write to a second file, as I did, or read the whole file into memory, and then rewrite it with the new text. Or, you could read just the part after the search string, and then reinsert that. I'm pretty sure that's the only way to do it.

    //Anders
    Reality is what you make up when you can't handle your fantasies.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Saudi Arabia, Gulf side, Qatif
    Posts
    142

    Thumbs up

    Thank you very much for your participation, I will email you if I find better solution,,,
    Thanks again and see you in other topic
    Regards

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