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

Adding info into log file

Hi ,

Attached a code that writes into a log file.

How can i edit the code so that it writes when is the string (strChanges ) is written?

eg:
10 Oct  16:05  text of strChanges
Private Sub ObjOPCGroup_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date)
    Dim i As Integer
    Dim strChanges As String    
For i = 1 To NumItems
        strChanges = strChanges & Array_Items(ClientHandles(i)) & " New Values " & ItemValues(i) & vbCrLf
    Next i
Call Write_in_File("C:\logfile.log", strChanges )
End Sub

*note: I am using vb script
Function Write_in_File(File, Content)
        Dim newFS
            Set newFS = CreateObject("Scripting.FileSystemObject")
            Set File_Name = newFS.OpenTextFile(File, 2, True)
            File_Name.Write Content
            File_Name.Close
            Set File_Name = Nothing
            Set newFS = Nothing
End Function

Open in new window

0
csharp_learner
Asked:
csharp_learner
  • 2
1 Solution
 
DhaestCommented:
>> How can i edit the code so that it writes when is the string (strChanges ) is written?

What exactly do you mean ?  Do you want to add a messagebox ?
Function Write_in_File(File, Content)
        Dim newFS
            Set newFS = CreateObject("Scripting.FileSystemObject")
            Set File_Name = newFS.OpenTextFile(File, 2, True)
            File_Name.Write Content
            File_Name.Close
            msgbox ("Content saved to file")
            Set File_Name = Nothing
            Set newFS = Nothing
End Function

Open in new window

0
 
csharp_learnerAuthor Commented:
What i mean is inside the logfile, there is a date and time to indicate when the string is written.

So when the string is successfully written when you opoen it it'll read something like

eg:
10 Oct  16:05  text of strChanges
10 Oct 16:17  text of strChanges
0
 
DhaestCommented:
Add the date when writing the content to the file

Like this:

File_Name.Write Now & " " & Content
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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