Editing external Notepad log file using VB application

Posted on 2003-03-13
Medium Priority
Last Modified: 2008-03-04
I have a VB6 application which basically installs various applications on a machine. These applications are novell delivered and the VB app pulls them in from an *.ini file. What i would like to do is have the program write into an existing log.txt file the names of the applications it installs.

I have it already writing the information into the registry using a module, but i am unsure how to get VB to write any information into an external notepad file.

Thanks everyone in advance
Question by:JasonRegan
LVL 14

Accepted Solution

aelatik earned 336 total points
ID: 8126497
Private Sub Form_Load()
    Const ForAppending = 8
    Const Create = True
    Dim MyFileSystemObject
    Dim MyLogFile
    Dim MyLogFileName
    Dim MyLogString
    MyLogFileName = "c:\filename.txt"
    Set MyFileSystemObject = CreateObject("Scripting.FileSystemObject")
    Set MyLogFile = MyFileSystemObject.OpenTextFile(MyLogFileName, ForAppending, Create)

        MyLogString = "This is the text"
        MyLogFile.write MyLogString
        MyLogFile.Writeline ""

    Set MyLogFile = Nothing
    Set MyFileSystemObject = Nothing

End Sub
LVL 43

Assisted Solution

TimCottee earned 332 total points
ID: 8126537
Hi JasonRegan,

This is actually very simple:

Dim intFHandle As Integer
intFHandle = FreeFile()
Open "C:\mylogfiles\Installation.txt" For Output As #intFHandle
Print #intFHandle,"Application Installation : MyNewApplication"
Close #intFHandle

And that is all there is to it. This simply outputs whatever you put in the second parameter of the Print # statement to the file specified in the Open statement.


Brainbench MVP for Visual Basic

Experts-Exchange Advisory Board Member
LVL 43

Expert Comment

ID: 8126551
Just a comment, don't use the filesystemobject unless you really have to! It requires IE to be installed on the client and the scripting runtime enabled (it may be disabled by a system administrator). Also it may add significant overhead to deployment. VB has native file functions as shown that can achieve almost everything you would need to do. The filesystemobject is available because it is necessary for VBScript which doesn't have the native file functions, I would caution strongly against its use in VB proper unless absolutely necessary.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 8128429
Here Here!

Someone else that hate the File Sucking Object. YES!

Assisted Solution

Diveblue earned 332 total points
ID: 8130082
Just a note - Tim's code is correct, but opening the file for output each time will overwrite previous lines. You may want to consider using the following, which will append to the end of the file.

Open "C:\mylogfiles\Installation.txt" For Append As #intFHandle

Expert Comment

ID: 8900175
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
LVL 49

Expert Comment

ID: 9692795
Moderator, my recommended disposition is:

    Split points between: aelatik and TimCottee and Diveblue

DanRollins -- EE database cleanup volunteer

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

612 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