Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Insert line into .log file.....

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

927 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