Solved

Insert line into .log file.....

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

738 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