Solved

Insert line into .log file.....

Posted on 2000-05-12
3
144 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
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now