• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

I need to create a history of all user events in a text file, anyone know how

I need to create a record of all events in a program as print it as data to a text file. I need to be able to get the users name, the filename, the date and time. To this I will add the processing used as strings. I ahave used code to write and read from ini file, will it be along those lines?
  • 2
  • 2
1 Solution
Mike TomlinsonMiddle School Assistant TeacherCommented:
Not sure exactly what you're asking for here...

Below is simple code that demonstrates how to output to a text file:

Option Explicit

Private outputLog As String

Private Sub Form_Load()
    outputLog = "c:\someFile.txt"
End Sub

Private Sub Command1_Click()
    Dim i As Integer
    For i = 1 To 10
        WriteLineToFile outputLog, "Line" & i
    Next i
End Sub

Private Sub WriteLineToFile(ByVal fileName As String, ByVal outputLine As String)
    On Error GoTo fileError
    Dim ff As Integer
    ff = FreeFile
    Open fileName For Append As #ff
    Print #ff, outputLine
    Close #ff
    Exit Sub
    MsgBox "Error writing to " & fileName & vbCrLf & Err.Description, vbExclamation, "Error " & Err.Number
End Sub
eneateAuthor Commented:
Thanks, what commands would I use to obtain the date time
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can do things like..

    ' this one is dependent upon your system settings
    Debug.Print Now ' 6/13/2006 7:55:19 AM
    Dim dt As String
    dt = Format(Now, "dd mmm yyyy")
    Debug.Print dt ' 13 Jun 2006
    Dim tm As String
    tm = Format(Now, "h:nn:ss am/pm")
    Debug.Print tm ' 7:57:43 am
    Dim dtTm As String
    dtTm = Format(Now, "dd mmm yyyy @ h:nn:ss am/pm")
    Debug.Print dtTm ' 13 Jun 2006 @ 7:58:56 am
eneateAuthor Commented:
Thanks, that gives me somewher to start from.
[ fanpages ]IT Services ConsultantCommented:
...further to Idle_Mind's response...

Debug.Print Format(Now, "Long Date") & " " & Format(Now, "Long Time")


Debug.Print Format(Now, "Short Date") & " " & Format(Now, "Short Time")

Can also be used, and take the format of the date/time presentation from the ("International Settings" or) "Regional and Language Options" (depending on which version of MS-Windows you are using) applet in the Windows Control Panel.

PS. You asked about the filename - did you mean the filename of the Visual Basic application (App.EXEName)?


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now