?
Solved

accumulative log

Posted on 2011-10-10
5
Medium Priority
?
252 Views
Last Modified: 2012-08-13
Hi,

The code i have currently only log in the current string.
How can i edit the code so that it "remembers" the old string plus add in the current string?

So the result is something like
10/10/2011 04:26:40 PM Strings
10/10/2011 04:26:45 PM Strings
11/10/2011 02:26:40 PM Strings


*Note: I am using vb script
Sub asd(o As GwxPick)
Call Write_in_File("C:\logfile.log", "Strings")
End Sub
Function Write_in_File(File, Content)
        Dim newFS
            Set newFS = CreateObject("Scripting.FileSystemObject")
            Set File_Name = newFS.OpenTextFile(File, 2, True)
            File_Name.Write Now & " " & Content
            File_Name.Close
            Set File_Name = Nothing
            Set newFS = Nothing
End Function

Open in new window

0
Comment
Question by:csharp_learner
  • 3
  • 2
5 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 36941372
Try another opening mode

' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8



http://www.computerperformance.co.uk/vbscript/vbscript_file_opentextfile.htm
Sub asd(o As GwxPick)
Call Write_in_File("C:\logfile.log", "Strings")
End Sub
Function Write_in_File(File, Content)
        Dim newFS
            Set newFS = CreateObject("Scripting.FileSystemObject")
            Set File_Name = newFS.OpenTextFile(File, 8, True)
            File_Name.Write Now & " " & Content
            File_Name.Close
            Set File_Name = Nothing
            Set newFS = Nothing
End Function

Open in new window

0
 

Author Comment

by:csharp_learner
ID: 36941386
Can it be coded in a way the new string is written on a new line instead?
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 36941412
Yes you can, just add a newline constant after writing each line. So the next one will start a a new line

File_Name.Write Now & " " & Content & vbCrLf
0
 

Author Closing Comment

by:csharp_learner
ID: 36941420
Thank you so much for your help.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 36941438
Glad to help you
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question