Solved

Insert line into .log file.....

Posted on 2000-05-12
3
186 Views
Last Modified: 2010-05-02
I created one log file by below mentioned way.

Sub CreateAfile
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile("c:\testfile.log", True)
    a.WriteLine("This is a test.")
    a.Close
End Sub

Now i want to add another lines below that line which is already written by me during previous session.

e.g.
This is a test.
This is my second test.

I mean i want to add another line during next session.

Let me know how do i do that ?

Thanks for your time in advance.

Thanks,
buddyp
0
Comment
Question by:buddyp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
Vbmaster earned 5 total points
ID: 2805624
Don't know why you are using the Scripting object, using simple VB statements you can create the file using code like

  Dim Filenr As Integer

  Filenr = FreeFile
  Open "c:\testfile.log" For Output As #Filenr
  Print #Filenr, "This is a test."
  Close #Filenr

This code has the same behaviour as your code above, but this code is approx. 1 mb smaller ('cause you do not need to add the scripting object as a dependency file).

Whenever you want to add a line to the file you can use code like this

  Dim Filenr As Integer

  Filenr = FreeFile
  Open "c:\testfile.log" For Append As #Filenr
  Print #Filenr, "This is my second test."
  Close #Filenr

This will append the line to the file and not delete the old data you have already stored inside the file.
0
 

Expert Comment

by:SpikeDog
ID: 2805632
Try setting your true to false. That should then add to the file instead of overwriting it.
Alternatively use OpenTextFile instead and use the IOMode as ForAppending.
0
 

Author Comment

by:buddyp
ID: 2805765
Vbmaster
Thanks a lot ! sir !

Take care,
buddyp
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 Month9 days, 15 hours left to enroll

623 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