Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Insert line into .log file.....

Posted on 2000-05-12
3
Medium Priority
?
188 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 20 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 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